0

I want to create 2 types of log 1 Debug log which will create all log another I want to create activity log I mean each method how much time took to execute or any specific info, I am using below log4j property file- please correct me, its logging all messages in only one file,in java I have instantiated both log object, kindly don't send any pointers or just Google because I have tried since last 2 days all options as described in Google, Thanks in advance for your kind support,

log4j.rootLogger=debugLog,reportsLog

log4j.appender.debugLog=org.apache.log4j.FileAppender
log4j.appender.debugLog.File=logs/debug.log
log4j.appender.debugLog.layout=org.apache.log4j.PatternLayout
log4j.appender.debugLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n

log4j.appender.reportsLog=org.apache.log4j.FileAppender
log4j.appender.reportsLog.File=logs/reports.log
log4j.appender.reportsLog.layout=org.apache.log4j.PatternLayout
log4j.appender.reportsLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n

log4j.category.debugLogger=INFO, debugLog
log4j.additivity.debugLogger=false

log4j.category.reportsLogger=DEBUG, reportsLog
log4j.additivity.reportsLogger=false
2
  • do you already have method logging in place and just need help with log4j? Commented Jan 16, 2015 at 5:38
  • yes just want to log in separate files different info. Commented Jan 16, 2015 at 7:44

1 Answer 1

1

Below log4j.properties file will configure the logger to log the messages with debug level to the logs/debug.log file. Messages with level INFO...FATAL are logged to logs/reports.log.

log4j.rootLogger=DEBUG, debugLog, reportsLog

log4j.appender.debugLog=org.apache.log4j.FileAppender
log4j.appender.debugLog.File=logs/debug.log
log4j.appender.debugLog.layout=org.apache.log4j.PatternLayout
log4j.appender.debugLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n
log4j.appender.debugLog.filter.f1=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.debugLog.filter.f1.LevelMax=DEBUG
log4j.appender.debugLog.filter.f1.LevelMin=DEBUG

log4j.appender.reportsLog=org.apache.log4j.FileAppender
log4j.appender.reportsLog.File=logs/reports.log
log4j.appender.reportsLog.layout=org.apache.log4j.PatternLayout
log4j.appender.reportsLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n
log4j.appender.reportsLog.filter.f1=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.reportsLog.filter.f1.LevelMax=FATAL
log4j.appender.reportsLog.filter.f1.LevelMin=INFO

log4j.category.debugLogger=DEBUG, debugLog
log4j.additivity.debugLogger=false

log4j.category.reportsLogger=INFO, reportsLog
log4j.additivity.reportsLogger=false
Sign up to request clarification or add additional context in comments.

4 Comments

How?Please can you help by editing my property file, Thanks in advance.
I posted the corrected first line of your property file. For possible other questions, there is to much information how do you use the logger in your code. The fixed line at least will produce output in both files. As a starting point.
This I have already did but its logging in only one file,all debug messages but I want some custom messages(info) in separate file(report.log) and all debug message in another(debug.log file),Please suggest me proper resolution,Thanks in advance
@SubOptimal- Many Thanks, some how its solved my issue,now I need to customize as per my requirement,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.