Configuring a class using a logger to log to a file with log4j

797 views Asked by At

Hi I have 4 classes that each share anonymous instances of a logger class (not my creation). I have added a log4j appender and set the logger to log to the appender file. The problem is that everything is logging to the file including Hibernate. How do I set up the classes only to log to this file?

Here is my present configuration file:

# Direct log messages to a file
log4j.appender.file=com.daniels.logging.RollingFileAppender
log4j.appender.file.File=daniels.log
log4j.appender.file.MaxFileSize=100MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.S} %-5p [%c{1}:%M] - %m%n
log4j.appender.file.append=true

# Root logger option
log4j.rootLogger=INFO, file

One of my classes is called SeriousEvent. If I would like this class to log to the file com.daniels.logging.RollingFileAppender how would I set this up? I'm new to logging so forgive me. I have looked through the documentation but I'm finding it hard getting a good example.

Thanks, Daniel

1

There are 1 answers

1
dansouza On

I think those links below can help you:

You also might see the Log4j documentation page in order to understand the appenders.

One question: did you develop a customized appender for your system? I'm asking that because you added on your file:

log4j.appender.file=com.daniels.logging.RollingFileAppender

Seeing on log4j docs, this property should be and component appender, such as:

log4j.appender.file=org.apache.log4j.RollingFileAppender