It's worth noting that people have set this up before (log file per level) and concluded it was not a good solution for them [1]. I tend to agree, better to log to a single file at the appropriate threshold and a log-file viewer/post-processor if you want to filter further later. It can be very annoying if you have all of your ERROR messages in one file, then you need to reconstruct an in-sequence collection of preceeding/trailing INFO and DEBUG messages from other files to put it into context for debugging.
If you do want to do it, I can see a number of ways and that people have used these previously. Have a look at the Filter API [2]. You might even get away with overriding AppenderSkeleton.isAsSevereAsThreshold(). Best Brett [1] http://stackoverflow.com/questions/6050074/log4j-with-writing-in-different-files [2] http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/Filter.html On 22 August 2012 23:54, adicj <[email protected]> wrote: > > hi all, > > Im new to log4j.i am trying to log the Info and error into two different > files. > here is my log4j.properties file > > # Direct info log messages to a log file > log4j.appender.infofile=org.apache.log4j.RollingFileAppender > log4j.appender.infofile.File=C\:\\infologing.log > log4j.appender.infofile.MaxFileSize=1MB > log4j.appender.infofile.MaxBackupIndex=10 > log4j.appender.infofile.layout=org.apache.log4j.PatternLayout > log4j.appender.infofile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L > - > %m%n > log4j.appender.infofile.Threshold=info > > # Direct error log messages to a log file > log4j.appender.errorfile=org.apache.log4j.RollingFileAppender > log4j.appender.errorfile.File=C\:\\errorloging.log > log4j.appender.errorfile.MaxFileSize=1MB > log4j.appender.errorfile.MaxBackupIndex=10 > log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout > log4j.appender.errorfile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L > - %m%n > log4j.appender.errorfile.Threshold=error > > # Direct log messages to stdout > 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{ABSOLUTE} %5p %c{1}:%L - > %m%n > log4j.appender.stdout.Threshold=info > > # Root logger option > log4j.rootLogger=info, infofile, errorfile > > But my infologing.log look like > > 19:05:39,028 ERROR ClassLogger:27 - error message 1 > 19:05:39,059 INFO ClassLogger:28 - well done > 19:05:39,090 INFO ClassLogger:29 - try it again @ :Wed Aug 22 19:05:39 IST > 2012 > 19:05:39,090 ERROR ClassLogger:30 - error message 2 > > But the errorloging.log is Working fine Like > > 19:05:39,028 ERROR ClassLogger:27 - error message 1 > 19:05:39,090 ERROR ClassLogger:30 - error message 2 > > This is my ClassLogger.java > > public static void main(String[] args) { > // TODO Auto-generated method stub > Logger > logger=Logger.getLogger(ClassLogger.class.getCanonicalName()); > > // this is to Locate Properties File****************** > > > PropertyConfigurator.configure("D:\\Workspace\\LoggerSample\\src\\log4j.properties"); > > logger.error("error message 1"); > logger.info("well done"); > logger.info("try it again @ :"+new Date().toString()); > logger.error("error message 2"); > } > > Please help me to solve this issue by gettting "info" Log only in > "infofile.log" file > > Thanks in Advance > Adi > > > -- > View this message in context: > http://old.nabble.com/Log4j-%3A-how-to-classify-loger-messages-tp34334503p34334503.html > Sent from the Log4j - Users mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
