Logging

Logging and configuration

We're using Log4j, so configuration is in $MUTANT_HOME/log4j.properties

To switch between debug and info modes, change the first word in the file

log4j.rootCategory=debug, R, stdout

to
log4j.rootCategory=info, R, stdout

Make sure the log folder is created: $MUTANT_HOME/log

Code: com.razie.pub.base.log

I use a simple generic wrapper for logging. All code uses Log.java and Log.Factory to create loggers. This can be mapped to any logging framework.

Use it either as a static

Log.logThis(xxx)

or instance per class:
public final static Log logger = Log.Factory.create (MyClass.class.getName());
logger.log (xxx);

The second version can print the specific class name.

Remote log access

The last NNN lines of log are available remotely via the web api: http://MYHOST:4444/mutant/control/GetLog or

Service("control").action("GetLog")

Typical log4j.properties

In case you're not familiar with log4j, you need a file log4j.properties in the classpath. Here's a typical content for the file:

log4j.rootCategory=debug, R, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%.1p %d{HH:mm:ss} %t> %m%n

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=log/mutant.log
log4j.appender.R.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%.1p %d{HH:mm:ss} %t> %m%n

This will log to the console (stdout) and files in the ./log folder.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License