我正在尝试在我的代码中添加日志语句。
使用 LogConfigurator,我在 MainActivity 中编写了以下代码 -
public class MainActivity extends Activity {
Logger log = Logger.getLogger(MainActivity.class);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogConfigurator logConfigurator = new LogConfigurator();
logConfigurator.setFileName(Environment.getExternalStorageDirectory()
+ File.separator + "MyApp" + File.separator + "logs"
+ File.separator + "log4j.txt");
logConfigurator.setRootLevel(Level.DEBUG);
logConfigurator.setLevel("org.apache", Level.ERROR);
logConfigurator.setFilePattern("%d %-5p [%c{2}]-[%L] %m%n");
logConfigurator.setMaxFileSize(1024 * 1024 * 5 * 1024 );
logConfigurator.setImmediateFlush(true);
logConfigurator.configure();
log.info("Execution of method onCreate started");
MyTask mTask = new MyTask();
mTask.execute();
log.info("Execution of method onCreate ended");
}
它工作正常。但是当我添加
Logger log = Logger.getLogger(JsonConversion.class);
在另一个名为 JsonConversion 的类和更多类中,我的 logcat 中出现以下错误
07-11 04:32:27.693: E/AndroidRuntime(3963): FATAL EXCEPTION: main
07-11 04:32:27.693: E/AndroidRuntime(3963): java.lang.StackOverflowError
07-11 04:32:27.693: E/AndroidRuntime(3963): at org.apache.log4j.CategoryKey.equals(CategoryKey.java:47)
07-11 04:32:27.693: E/AndroidRuntime(3963): at java.util.Hashtable.get(Hashtable.java:271)
07-11 04:32:27.693: E/AndroidRuntime(3963): at org.apache.log4j.Hierarchy.getLogger(Hierarchy.java:273)
07-11 04:32:27.693: E/AndroidRuntime(3963): at org.apache.log4j.Hierarchy.getLogger(Hierarchy.java:247)
07-11 04:32:27.693: E/AndroidRuntime(3963): at org.apache.log4j.LogManager.getLogger(LogManager.java:228)
07-11 04:32:27.693: E/AndroidRuntime(3963): at org.apache.log4j.Logger.getLogger(Logger.java:117)
07-11 04:32:27.693: E/AndroidRuntime(3963): at com.example.news_android_mobile_application_cd.JsonConversion.<init>(JsonConversion.java:25)
07-11 04:32:27.693: E/AndroidRuntime(3963): at com.example.news_android_mobile_application_cd.MainActivity.<init>(MainActivity.java:25)
我添加了 log4j-1.2.17.jar 和 android-logging-log4j-1.0.3.jar 。有人可以帮帮我吗?