我是靠谱客的博主 外向哑铃,最近开发中收集的这篇文章主要介绍android log to file,Logback-android: Log not getting writen to a file,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

问题

Trying to redirect the log messages using logback-android, so that messages can be saved in a file. However, it is not getting saved into a file.

This is my logback.xml file configration, which is stored under src/main/assets in my Android Studio

/data/com.test.equa/files/log/foo.log

%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n

This is piece of code where i am initiating the logging.

@Override

public void onCreate() {

super.onCreate();

loadData();

Logger log = LoggerFactory.getLogger(MyActivity.class);

log.error("Application Data setup in progress");

}

Issue: I continue to see the messages in the logcat, but i expect them to be stored in my android sd card memory.

Added the user permission in manifest for writting the logs in the sd card

Am i missing some thing in this configuration, as i don't see any errors or message in my logcat for any configuration errors also. Can some one help me here

回答1:

Did you try to add configuration to AndroidManifest.xml?

Example manifest (from this link):

package="com.example"

android:versionCode="1"

android:versionName="1.0" >

android:minSdkVersion="8"

android:targetSdkVersion="16" />

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

android:name="com.example.MainActivity"

android:label="@string/app_name" >

name="LOGCAT"

class="ch.qos.logback.classic.android.LogcatAppender" >

%logger{0}

[ %thread ] %msg%n

回答2:

For Android 6+ You have to define permissions manually in settings for your application. Otherwise logback will not be allowed to write to external storage even if you grant WRITE_EXTERNAL_STORAGE permission in manifest.xml.

I took solution from here.

回答3:

For me it was kind of solved by the first comment of Nija on the question.

My file tag now looks like this:

/sdcard/Android/data/[my-package-from-AndroidManifest]/logs.log

The weird think is though, that the logs.log file appeared on my internal storage under the given path (without /sdcard/).

My phone is running Android 6.0.1 in case thats relevant.

Concluding my answer is to try the above file path and check internal storage in case the other answers don't work.

Update:

Just wanted to open the log file on the computer, but couldn't find it. I can still find it with any storage access app (e.g. file commander) on the phone itself. But when looking at exactly the same folder with the PC it's not there. So check it out with a storage access app when that's good enough for you.

来源:https://stackoverflow.com/questions/28059512/logback-android-log-not-getting-writen-to-a-file

最后

以上就是外向哑铃为你收集整理的android log to file,Logback-android: Log not getting writen to a file的全部内容,希望文章能够帮你解决android log to file,Logback-android: Log not getting writen to a file所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部