Logback-android:日志未写入文件 [英] Logback-android: Log not getting writen to a file

查看:229
本文介绍了Logback-android:日志未写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用logback-android重定向日志消息,以便可以将消息保存在文件中.但是,它并没有保存到文件中.

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.

这是我的logback.xml文件配置,存储在我的Android Studio中的 src/main/assets

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

<configuration debug="true">
    <!-- Create a file appender for a log in the application's data directory -->
    <appender name="FILE" class="ch.qos.logback.classic.android.FileAppender">
        <file>/data/com.test.equa/files/log/foo.log</file>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- Write INFO (and higher-level) messages to the log file -->
    <root level="INFO">
        <appender-ref ref="FILE" />
    </root>
</configuration> 

这是我启动日志记录的代码.

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");



    }

问题:我继续在logcat中看到消息,但我希望它们会存储在我的android sd卡内存中.

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

在清单中添加了用于在SD卡中写入日志的用户权限

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

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

我是否在此配置中缺少某些内容,因为我在logcat中也看不到任何错误或任何配置错误的消息.有人可以帮我吗

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

推荐答案

您是否尝试将配置添加到AndroidManifest.xml?

Did you try to add configuration to AndroidManifest.xml?

清单示例(来自此链接):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <logback>
        <configuration>
          <appender
              name="LOGCAT"
              class="ch.qos.logback.classic.android.LogcatAppender" >
              <tagEncoder>
                  <pattern>%logger{0}</pattern>
              </tagEncoder>
              <encoder>
                  <pattern>[ %thread ] %msg%n</pattern>
              </encoder>
          </appender>

          <root level="WARN" >
              <appender-ref ref="LOGCAT" />
          </root>
        </configuration>
    </logback>

</manifest>

这篇关于Logback-android:日志未写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆