Reputation: 404
Hi all IBM ICN Developers,
I am working on writing an ICN plugin. I want my logger statements to get logged into a separate file rather than going in System.Out file. Has anyone configured the custom logging by using Log4J libraries in an ICN Plugin? I tried configuring exactly as we do in a Java program but the log file is not getting generated in the configured directory. Here is my log4j.properties file
# Root logger option
log4j.rootLogger=INFO, file
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/tmp/MyPlugin.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
I tried placing the log4j.properties file inside /src folder and even directly under / folder.
Can someone please help me with some pointers?
Thanks in advance..
Upvotes: 0
Views: 766
Reputation: 404
Solved. Created a separate class for initializing logger instance. The init method is called from the code which gets called in the beginning of the plugin execution.
public class LoggingUtil {
private static LoggingUtil instance = null;
private static RollingFileAppender rfa = null;
protected LoggingUtil() {
}
public static LoggingUtil getInstance() {
if(instance == null) {
instance = new LoggingUtil();
}
return instance;
}
public void init() {
if (rfa == null) {
try{
LoggerContext context = (LoggerContext)LogManager.getContext(false);
File file = new File("//opt//log4j.xml");
context.setConfigLocation(file.toURI());
System.out.println("Log4J properties configured...");
}catch(Exception e){
System.out.println("ERROR occurred while loading properties file");
e.printStackTrace();
}
}
}
}
Upvotes: 0
Reputation: 1
Which version of ICN are you developing on. I think(!) starting 3.0.9 IBM removed log4j in favor of JUL (Java Utility Logging).
Hope this helps.
Upvotes: 0