我有一个RCP应用程序,我在其中使用log4j进行日志记录。为此,我在MANIFEST.MF文件中添加了log4j jar。并在根文件夹下添加了log4j.properties。但是,当我启动应用程序(导出产品后)(使用-console -consolelog)时,它会在控制台中生成日志。但令人惊讶的是,日志文件未更新。
但是当我从eclipse运行应用程序时会生成日志文件。
现在MANIFEST.MF看起来像这样 -
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: EditorApp
Bundle-SymbolicName: EditorApp;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: APP
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
com.ibm.icu,
org.eclipse.jface.databinding,
org.eclipse.core.databinding.property,
org.eclipse.core.databinding.observable,
org.eclipse.core.databinding.beans,
org.eclipse.core.databinding,
org.eclipse.core.resources;bundle-version="3.9.1",
org.apache.log4j;bundle-version="1.2.15"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: com.app.editor;
uses:="org.osgi.framework,
org.eclipse.ui,
org.eclipse.jface.action,
org.eclipse.equinox.app,
org.eclipse.jface.resource,
org.eclipse.ui.application,
org.eclipse.ui.plugin",
com.app.editor.actions;uses:="org.eclipse.jface.action",
com.app.editor.beans,
com.app.editor.functionalities;
uses:="org.eclipse.swt.graphics,
org.eclipse.swt.widgets,
org.eclipse.jface.dialogs,
javax.swing.tree",
com.app.editor.handlers;uses:="org.eclipse.core.commands",
com.app.editor.perspectives;uses:="org.eclipse.ui",
com.app.editor.views;
uses:="com.app.editor.beans,
org.eclipse.swt.widgets,
org.eclipse.swt.custom,
com.app.editor.functionalities,
org.eclipse.core.databinding,
org.eclipse.jface.viewers,
org.eclipse.ui.part"
Bundle-ClassPath: .,
library/log4j-1.2.17.jar,
library/mariadb-java-client-1.2.3.jar
log4j.properties如下所示:
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
#log4j.appender.file.File=C:\\Srijani\\Personal Workspace\\RCP\\EditorApp\\log\\Application.log
log4j.appender.file.File=C:\\Users\\srijani.ghosh\\Desktop\\log\\Application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.dbLog=org.apache.log4j.RollingFileAppender
#log4j.appender.dbLog.File=C:\\Srijani\\Personal Workspace\\RCP\\EditorApp\\log\\database_connection.log
log4j.appender.dbLog.File=C:\\Users\\srijani.ghosh\\Desktop\\log\\database_connection.log
log4j.appender.dbLog.MaxFileSize=5MB
log4j.appender.dbLog.MaxBackupIndex=10
log4j.appender.dbLog.layout=org.apache.log4j.PatternLayout
log4j.appender.dbLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.category.fileLogger=DEBUG, file
log4j.additivity.fileLogger=false
log4j.category.dbLogger=DEBUG, dbLog
log4j.additivity.dbLogger=false
我在我的视图文件中使用这样的记录器:
private static final Logger LOGGER = Logger.getLogger("fileLogger");
LOGGER.info("Starting application...");
可能的原因是什么?
提前致谢!
答案 0 :(得分:0)
我将以下这些行添加到代码的入口点。
String path = <path to log4j.propertties>;
PropertyConfigurator.configure(path);