Android Log4J - 无法找到课程

时间:2014-08-25 10:39:55

标签: java android eclipse log4j

我在android环境中使用了Log4J。
但是,它不起作用。

以下链接是我关于Log4J的logcat消息。
(我没有声誉,我无法上传截图。)

https://lh4.googleusercontent.com/-5C4VV-h8q-c/U_sQLgqBiAI/AAAAAAAAA0I/PgZu7no2q6w/w1159-h538-no/logcat.png


这是我的java bild路径图片链接。
https://lh6.googleusercontent.com/-W92XFbt1Cqg/U_sQLahEBOI/AAAAAAAAA0A/ybEi4P6CWFw/w810-h607-no/build%2Bpath.png


ConfigureLog4J.java

package com.example.log4j_test;

import java.io.File;

import org.apache.log4j.Level;

import android.os.Environment;
import de.mindpipe.android.logging.log4j.LogConfigurator;

public class ConfigureLog4J {

     public static void configure() {
            final LogConfigurator logConfigurator = new LogConfigurator();

            logConfigurator.setFileName(Environment.getExternalStorageDirectory() + File.separator + "myapp.log");
            logConfigurator.setRootLevel(Level.DEBUG);
            // Set log level of a specific logger
            logConfigurator.setLevel("org.apache", Level.ERROR);
            logConfigurator.configure();
        }
}



MainActivity.java

package com.example.log4j_test;

import org.apache.log4j.Logger;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

    private final Logger logger = Logger.getLogger(MainActivity.class);

    static {
        ConfigureLog4J.configure();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        logger.info("This message should be seen in log file and logcat");
    }
}



log4j.properties

# Log4j Setting file
log4j.rootLogger=INFO, console

# Daily file log
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.File=C:/Data/Log/data.log
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=[%d{HH:mm:ss}][%-5p](%F:%L)-%m%n

# Console log
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-5p%l -%m%n

# log level and appender
#log4j.logger.name.of.the.package.one=DEBUG, console
log4j.logger.com.example.log4j_test=DEBUG, console

#log4j.logger.name.of.the.package.two=INFO, logfile
log4j.logger.com.example.log4j_test=INFO, logfile



的AndroidManifest.xml

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

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".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>

</manifest>


请给我一些建议。
感谢。

0 个答案:

没有答案