Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

I use log4j and would like to route the output of certain Loggers to specific files.

I already have multiple appenders in place. Now, to make debugging easier, I want to tell log4j that the output generated by a specific class (e.g. foo.bar.Baz) should be written to a specific log file.

Can this be done?

1 Answer

0 votes
by (46k points)

An example:

log4j.rootLogger=ERROR, logfile

log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender

log4j.appender.logfile.datePattern='-'dd'.log'

log4j.appender.logfile.File=log/radius-prod.log

log4j.appender.logfile.layout=org.apache.log4j.PatternLayout

log4j.appender.logfile.layout.ConversionPattern=%-6r %d{ISO8601} %-5p %40.40c %x - %m\n

log4j.logger.foo.bar.Baz=DEBUG, myappender

log4j.additivity.foo.bar.Baz=false

log4j.appender.myappender=org.apache.log4j.DailyRollingFileAppender

log4j.appender.myappender.datePattern='-'dd'.log'

log4j.appender.myappender.File=log/access-ext-dmz-prod.log

log4j.appender.myappender.layout=org.apache.log4j.PatternLayout

log4j.appender.myappender.layout.ConversionPattern=%-6r %d{ISO8601} %-5p %40.40c %x - %m\n

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...