I finally got log4j setup with spring mvc, my log4j properties looks like:
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Root logger option
log4j.rootLogger=trace, stdout
Now I don’t want to see any output except from my own code, is there a way to restrict all log messages to a specific namespace?
When I go into production, I don’t want any trace/debug information logged, I guess I have to create a file appender but how would I go about restricting the log messages to only severe type log messages like in a try/catch or something unexpected?
For example (using a
ConsoleAppeneder, but same difference):This logs at the
INFOlevel by default, except for theyour.package.to.debugand spring-aop packages, logged at theDEBUGlevel. Mix and match levels and packages however required.I’d be wary of not putting
INFOinto production unless you never need to debug anything, though–particularly during startup,INFOis really important. It can also be used to provide general system information.Also, the
%Lpattern is pretty slow. Fine for rareWARNING/etc. logs, not so much for normal operational logging.