0

I have to implement log4j in plugin project. after that i want to export a jar from this project and put this jar to the another eclipse plugin folder. For this i have create log4j.properties file here is code,

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=D:\\log4j-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 

and also add this code to the Activator.java,

 private static Logger logger=Logger.getLogger("Automatics_plugin");

"Automatics_plugin" is my project name.thereafter also add log4j .jar in project configuration build path and add this log4j.jar to the MANIFEST.MF in plugin.xml. Also i have write a code in Activator.java class in start()

URL confURL = getBundle().getEntry("log4j.properties");
PropertyConfigurator.configure(FileLocator.toFileURL(confURL).getFile());  

after export a jar and put this jar to another eclipse i got an exception "org.eclipse.core.runtime.CoreException: Plug-in Automatics_plugin was unable to load class com.automatics_plugin.login.view.OpenView.".then I excluded this code and again export jar and that time it will running succesfully. but log4j still failed to create on local. Please look this issue. Advance thanks.

Biswabir
  • 19
  • 8
  • first of all to the `getLogger` is better to give the MyClass.class - just to know in which class you are. Second the `log4j.properties` file shoul be under `src/main/resources`. Third the `log4j.appender.file.File` says where the file is saved - check there (if you want to be save in the project, just give a name without a path) – Edwin Jun 07 '17 at 12:18
  • 1
    Possible duplicate of https://stackoverflow.com/q/7994883/2670892 – greg-449 Jun 07 '17 at 12:18
  • it works for eclipse plugin application. if i export a jar and run this jar on other ecclipse, it not works. – Biswabir Jun 07 '17 at 12:51

0 Answers0