0

i was trying to redirect the log to console and two different log files..

this is my log4j.properties file:

log4j.rootLogger = DEBUG, console, file, csv


log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = %d{HH:mm:ss} %5p [%t] - %c.%M - %m%n


log4j.appender.file = org.apache.log4j.FileAppender
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern = %d %5p [%t] - %L %c.%M - %m%n
log4j.appender.file.File=./log/logfile.log


log4j.appender.csv = org.apache.log4j.FileAppender
log4j.appender.csv.layout = org.apache.log4j.PatternLayout
log4j.appender.csv.layout.ConversionPattern =%m%n
log4j.appender.csv.File = ./log/log.csv

now the problem is that the logging is happening, but both the files have both the logs that were meant to be logged separately in different files.. i really dont know where am i going wrong! can anyone please help me out??

Venkatesh
  • 79
  • 1
  • 1
  • 10
  • ---------- Please follow the link in this post http://stackoverflow.com/questions/9652032/how-can-i-create-2-separate-log-files-with-one-log4j-config-file – Sridhar Mar 12 '14 at 06:30
  • I tried this method too already!.. but this wasn't working for me.. – Venkatesh Mar 12 '14 at 06:40

1 Answers1

0

Log4j does not easily allow for splitting logs between multiple files. The basic idea is that all log statements are considered equal and should be treated equally.

If you were using slf4j as the API you could easily switch the backend from log4j to logback which has SiftingAppender for exactly this purpose.

http://logback.qos.ch/manual/loggingSeparation.html

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347