Nixing screen output with log4j

Viewed 2525

One of the irritating things with log4j is that it always wants to dump stuff to the screen. I don't need that if I'm logging to a file. I'm sure it's in how I set up the log4j.properties file. Getting all of this configuration stuff ironed out is frustrating! :-)

For a program I'm currently calling Balancer, this is how I'm doing my logger initialization. Perhaps it is wrong or something.

static Logger log = Logger.getLogger(Balancer.class);

A partial dump of my log4j.properties:

log4j.rootLogger=fatal, stdout
log4j.logger.Balancer=fatal, rollingLog

# I still don't understand how category stuff works yet
log4j.category.Balancer=info, BalancerLog

#### First appender writes to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p %d [%t] (%F:%L) - %m%n

#### Second appender writes to a file
# Control the maximum log file size
# Archive log files (ten backups here)
log4j.appender.rollingLog=org.apache.log4j.RollingFileAppender
log4j.appender.rollingLog.File=default.log
log4j.appender.rollingLog.MaxFileSize=10000KB
log4j.appender.rollingLog.MaxBackupIndex=10
log4j.appender.rollingLog.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingLog.layout.ConversionPattern=%5p %d [%t] (%F:%L) - %m%n

log4j.appender.BalancerLog=org.apache.log4j.RollingFileAppender
log4j.appender.BalancerLog.File=Balancer.log
log4j.appender.BalancerLog.MaxFileSize=100000KB
log4j.appender.BalancerLog.MaxBackupIndex=10
log4j.appender.BalancerLog.layout=org.apache.log4j.PatternLayout
log4j.appender.BalancerLog.layout.ConversionPattern=%5p %d [%t] (%F:%L) - %m%n

I get how the rootLogger sends stuff to the stdout appender. Is there a /dev/null appender? You have to have at least one appender.

Anyway, if nothing else, my basic work-around now is to send screen output to /dev/null. BTW, my Java programs run in a scheduled batch environment (no GUI). Having to clean up spooled files (yes this is on an AS/400) is a bit of a pain, although that can be automated as well.

1 Answers
Related