1
我想在我的代碼中添加日誌語句。用log4j登錄stackoverflow錯誤
使用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");
}
一切正常。但是,當我在一個名爲JsonConversion另一個類添加
Logger log = Logger.getLogger(JsonConversion.class);
和一些更多的類,我得到以下錯誤在我的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的日誌記錄-log4j-1.0.3.jar。 有人可以幫我嗎?
你真的可以在Android手機上有5GB文件嗎?而且,1024 * 1024 * 5 * 1024'不是您認爲的,因爲計算超過了'Integer.MAX_VALUE'。 –
@EricJablow耶!那是我的錯誤。我現在創建了5 KB(5 * 1024)的大小,但仍然是錯誤! – viedee