开发者

log4j, foreign logging

When my logger is set to "all", i am seeing messages that my code does not explicitly place. I am using a jar a friend of mine gave me to do some things (and i suspect he is logging stuff himself)

I would like to ONLY log stuff I ask to be logged by issuing the

logger.info ("something clever"); command

Below is my log4j.properties

please advise.

# ***** Set root logger level to WARN and its two appenders to stdout and R.
log4j.rootLogger=all, R

# ***** R is set to be a RollingFileAppender.
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log/something.log
# ***** Max file size is set to 100KB
log4j.appender.R.MaxFileSize=100KB
# ***** Kee开发者_如何学运维p one backup file
log4j.appender.R.MaxBackupIndex=1
# ***** R uses PatternLayout.
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n


Take a look at this excellent log4j cheatsheet:

  • http://www.johnmunsch.com/projects/Presentations/docs/Log4J/log.properties

Basically, you need to set something like this:

log4j.rootCategory=error, R
log4j.category.com.your.package=debug

or, alternatively:

log4j.category.com.your.friends.package=error

Replace the package names as necessary.

These would make the root logger set to error (so any package - including other libraries you might be using, like Hibernate, Spring, etc.) will not log anything low-level (debug, info, warn), but log only errors.

It will also set your package (include your top level package or packages) to log on a debug level, so all your loggers will log normally. It will also set your friend's package to error, so it doesn't output anything.

If you have a common root package, just use it. E.g. if you have packages:

  • com.example
  • com.example.a
  • com.example.a.aa
  • com.example.b
  • com.example.c.d

just include com.example and it will inherit for the packages below by default.

You could, of course, override it, e.g. specify:

  • com.example - warn
  • com.example.a.aa - debug

or something similar. Take a look here for a detailed explanation:

  • http://logging.apache.org/log4j/1.2/manual.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜