Question

I have a single log4j.properties file in the server and to applications deployed in the server.The requirement is to create separate loggers for the application I defined this in my application

# Root logger option
log4j.rootLogger=INFO, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/opt/ibm/WebSphere/AppServer/profiles/MDMServer/logs/damcoLoging.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
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

   #logging for jbpm
log4j.logger.jbpmLogger=INFO, jbpmLogger
log4j.appender.jbpmLogger=org.apache.log4j.RollingFileAppender
log4j.appender.jbpmLogger.maxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.jbpmLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.jbpmLogger.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.jbpmLogger.File=/opt/ibm/WebSphere/AppServer/profiles/MDMServer/logs/jbpmLogging.log
log4j.additivity.jbpmLogger=false

In my java class I have done this for the secondary logger

 Logger logger=Logger.getLogger("jbpmLogger");

Now the logs are getting generated properly.But for the secondary logger I want to set the class name as well.So that I can know from which class the log is generating. Currently the log for the secondary logger looks like this

INFO  jbpmLogger:8 - Hi

Is it possible to set the class name as well?

No correct solution

OTHER TIPS

You can add the class name to the output Pattern with %C, although the docs warn that this is slow. Is this what you want?

Or since onegetLogger() method takes a String, you could concatenate the class and your "jbpmLogger" if you wanted to. And since the naming is hierarchical, still just using your single logger in the configuration file. e.g.

Logger logger = getLogger("jbpmLogger." + this.getClass().getName());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top