文件中不生成日志
Logs are not generated in the files
我有一个示例 RCP 项目 HelloWorldRCP
。
我已经添加了 log4j。为此,我在 class 路径(路径:root_folder\lib\log4j-1.2.17.jar)、MANIFEST.MF、[=42] 中添加了 log4j.jar =].此外,log4.properties 存储在安装位置。所以,它直接从那里读取数据。
它们看起来如下:
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:\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
log4j.category.fileLogger=DEBUG, file
log4j.additivity.fileLogger=false
MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloWorldRCP
Bundle-SymbolicName: HelloWorldRCP;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: helloworldrcp.Activator
Require-Bundle: org.apache.log4j;bundle-version="1.2.15",
org.eclipse.ui,
org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
lib/log4j-1.2.17.jar
build.properties
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
lib/log4j-1.2.17.jar
我在 Application.java
中使用记录器
public Object start(IApplicationContext context) throws Exception {
BasicConfigurator.configure();
String log4jConfPathBase = Platform
.getInstallLocation()
.getURL()
.getPath()
.substring(
1,
Platform.getInstallLocation().getURL().getPath()
.length() - 1);
String log4jConfPath = log4jConfPathBase + "/log4j.properties";
PropertyConfigurator.configure(log4jConfPath);
LOGGER.debug("STARTING APPLICATION ..");
Display display = PlatformUI.createDisplay();
try {
int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART)
return IApplication.EXIT_RESTART;
else
return IApplication.EXIT_OK;
} finally {
display.dispose();
}
}
问题是:当我在 运行 项目中时,日志出现在 Eclipse 控制台中,而不是日志文件中。但也不给我任何错误。
有什么可能的原因吗?
谢谢!
抱歉这个问题,重启eclipse后,它开始工作正常!!!
我有一个示例 RCP 项目 HelloWorldRCP
。
我已经添加了 log4j。为此,我在 class 路径(路径:root_folder\lib\log4j-1.2.17.jar)、MANIFEST.MF、[=42] 中添加了 log4j.jar =].此外,log4.properties 存储在安装位置。所以,它直接从那里读取数据。
它们看起来如下:
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:\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
log4j.category.fileLogger=DEBUG, file
log4j.additivity.fileLogger=false
MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloWorldRCP
Bundle-SymbolicName: HelloWorldRCP;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: helloworldrcp.Activator
Require-Bundle: org.apache.log4j;bundle-version="1.2.15",
org.eclipse.ui,
org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
lib/log4j-1.2.17.jar
build.properties
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
lib/log4j-1.2.17.jar
我在 Application.java
中使用记录器public Object start(IApplicationContext context) throws Exception {
BasicConfigurator.configure();
String log4jConfPathBase = Platform
.getInstallLocation()
.getURL()
.getPath()
.substring(
1,
Platform.getInstallLocation().getURL().getPath()
.length() - 1);
String log4jConfPath = log4jConfPathBase + "/log4j.properties";
PropertyConfigurator.configure(log4jConfPath);
LOGGER.debug("STARTING APPLICATION ..");
Display display = PlatformUI.createDisplay();
try {
int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART)
return IApplication.EXIT_RESTART;
else
return IApplication.EXIT_OK;
} finally {
display.dispose();
}
}
问题是:当我在 运行 项目中时,日志出现在 Eclipse 控制台中,而不是日志文件中。但也不给我任何错误。
有什么可能的原因吗?
谢谢!
抱歉这个问题,重启eclipse后,它开始工作正常!!!