I use log4j.properties and configured as below to get separate log files:

# Root category
log4j.rootCategory=INFO,R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern for standard output
log4j.appender.stdout.layout.ConversionPattern=%d [%-5p] %c{2} - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log/application.log
log4j.appender.R.MaxFileSize=3000KB
# Keep forty backup files
log4j.appender.R.MaxBackupIndex=20
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.additivity.com.memory.log=false
log4j.additivity.com.cpu.log=false
log4j.appender.R.layout.ConversionPattern=%d [%-5p] - %m%n

# Log for Memory Usage
log4j.category.com.memory.log=DEBUG,memory
log4j.appender.memory=org.apache.log4j.RollingFileAppender
# log4j.appender.memory.DatePattern='.'yyyy-MM-dd
log4j.appender.memory.File=log/Memory_Usage.log
log4j.appender.memory.layout=org.apache.log4j.PatternLayout
log4j.additivity.com.cpu.log=false
log4j.appender.memory.layout.ConversionPattern=%d [%-5p] - %m%n

# Log for CPU Usage
log4j.category.com.cpu.log=DEBUG,cpu
log4j.appender.cpu=org.apache.log4j.RollingFileAppender
# log4j.appender.cpu.DatePattern='.'yyyy-MM-dd
log4j.appender.cpu.File=log/Cpu_Usage.log
log4j.appender.cpu.layout=org.apache.log4j.PatternLayout
log4j.additivity.com.memory.log=false
log4j.appender.cpu.layout.ConversionPattern=%d [%-5p] - %m%n

Within the application, I use:

Logger memoryLog = Logger.getLogger("com.memory.log");
Logger cpuLog = Logger.getLogger("com.cpu.log");

cpuLog.info("This is cpu log");  --> Writes to Cpu_Usage.log
memoryLog.info("This is memory log");  --> Writes to Memory_Usage.log

Logger.info("Sample.java","Application log"); --> Writes to application.log
-- 
View this message in context: 
http://www.nabble.com/Logging-issue-with-logginf-to-seperate-log-files-tp22170033p22175424.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to