日志不会在文件中生成

时间:2016-02-03 10:29:36

标签: java eclipse logging eclipse-rcp rcp

我有一个示例RCP项目HelloWorldRCP。 我已经添加了log4j。为此,我在build.properties的MANIFEST.MF中的类路径(patha:root_folder \ lib \ log4j-1.2.17.jar)中添加了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中使用logger

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控制台,而不是日志文件。但也没有给我任何错误。

任何可能的原因?

谢谢!

1 个答案:

答案 0 :(得分:0)

很抱歉这个问题,在重新启动的日食之后,它开始正常工作!!!

相关问题