Search code examples
javalogginglog4jeclipse-rcprcp

Log files are not generated while running RCP product file


I have a RCP application in which I am using log4j for logging purpose. For that I have added log4j jar in MANIFEST.MF file. and also added log4j.properties under the root folder. But, when I am starting the application (after export the product), (with -console -consolelog), it produces the logs in console. But suprisingly, log files are not updated.

But log files are generated when I am running the application from eclipse.

Now the MANIFEST.MF looks like this -

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 looks like this:

# 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

I am using the logger like this in my view files:

private static final Logger LOGGER = Logger.getLogger("fileLogger");
LOGGER.info("Starting application...");

What can be the probable cause for this?

Thanks in advance!


Solution

  • I added these following lines to the entrypoint of the code..

     String path = <path to log4j.propertties>;
     PropertyConfigurator.configure(path);