有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

文件中不生成java日志

我有一个样本RCP项目HelloWorldRCP。 我已经添加了log4j。为此,我添加了log4j。类路径中的jar(路径A:root\u folder\lib\log4j-1.2.17.jar),在清单中。MF,内置。财产。还有,log4。中的属性存储在安装位置。因此,它直接从那里读取数据
具体如下:

log4j。属性

# 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

显示。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

构建。属性

source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
               META-INF/,\
               .,\
                lib/log4j-1.2.17.jar

我在应用程序中使用记录器。爪哇

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) 个答案

  1. # 1 楼答案

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