Search code examples
javaeclipseloggingeclipse-rcprcp

Logs are not generated in the files


I have a sample RCP project HelloWorldRCP . I have added log4j to it. For that purpose, I have added the log4j.jar in the class path (patha : root_folder\lib\log4j-1.2.17.jar), in MANIFEST.MF, in build.properties. Also, log4.properties in stored in the installed location. So, it is reading data directly from there.
They looks as follows:

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

I am using logger in 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();
    }

}

The problem is: when I am running the project, logs are coming in Eclipse console, and not in the log files. But also doesn't give me any errors.

Any probable reasons?

Thanks!


Solution

  • Sorry for the question, After the restarted eclipse, it started working fine!!!