MentaLog provides a very flexible way to configure your logs through a programmatic API. The rules are:
java -cp lib/mentalog.jar:. -DlogFile=false -DlogColors=true -DwarnColor=30 -DlogSynchronized=true -DlogAddEncoder=com.mypacket.encoder.MyEncoder com.mypacket.MyProgram
It is important to note that the values you pass in the command line have PRECEDENCE over the values you configure in your code by calling the appropriate Log.setXXX methods, *unless* you are calling them from inside a configuration class as we will see below.
package com.mypacket; import static org.mentalog.Log.*; public class MyConfiguration implements Configuration { @Override public void configure() { Log.setFile(true); Log.setDir("/var/log/myLogs"); Log.setLevel(Warn); } }
Just remember about precedence. The class configuration has precedence over -D option which in turn has precedence over Log.setXXXXX methods. To be clear, if you pass a configuration class with Log.setFile(false) and you perform a call somewhere in your program to Log.setFile(true), this last call will be ignored. You can turn on -DlogShowBypassedConfig=true to see in your logs if any of your config calls are being ignored somewhere in your code.
The complete list of config parameters you can pass in the command line are:
logConsole - Log to the console (System.out) instead of file (Default = true)
logFile - Log to the a file instead of to the console (Default = false)
logLevel - The level of the log (Debug, Info, Warn, Error, Alert and Fatal) (Default = Warn)
logDir - The directory where to place the files (Default = ".")
logSynchronized - Should your logs be synchronized or not (Default = false)
logColors - Should you use colors for your logs (only applicable to console logging) (Default = false)
logAddEncoders, logAddEncode, logSetEncoders - And a new encoder to the default list or set a new list of encoders yourself (bypassing the default ones)
logTimestamper - The timestamper to be used by this log when calculating the time of each log. (Default = org.mentalog.timestamper.MillisTimestamper)
logTimeZone - The timezone to be used by this log when calculating the time of each log. (Default = TimeZone.getDefault())
logShowBypassedConfig - Log any configuration that was bypassed/ignored due to -D options or a config file. (Default = false)
logShowBypassedConfigLevel - In what log level to log the information above. (Default = Warn)
logNoSpaceAfterEqualSign - Do not separate two objects if the first one ends with a '=' sign. Ex: Warn.log("a=", 3) will print 'a=3' instead of 'a= 3' (Default = true)
logNoSpaceBetweenObjects - Do no place a space between objects. Ex: Warn.log("sergio", "is", "crazy") will print "sergioiscrazy" (Default = false)
logShowClassAndLineNumber - Show the class and the line number where the logging happened. (For debugging only) (Default = false)
logFilter - Filter the classes that you want to be logged, ignoring all other ones. Ex: logFilter=com.mypackage.complex.*, com.mypackage.util.SystemUtils (Default = null)
logBenchmark - Benchmark the time the logging is taking from your application, in other words, the total time, min time, max time and average time of your log operations. (Default = false)
logBufferSize - The buffer size to use for the logging. (Default = 1024 * 10)
logMemoryMappedBufferSize - The size of the file that will be mapped to memory (default = 50Mb)
logMemoryMappedBufferThreshold - The threshold before rolling the memory mapped byte buffer into a new one (default = 0.8)
logAlertOnBufferRoll - Alert if log file gets too big and requires a byte buffer roll which can be expensive (default = false)
logCacheOnBufferRoll - Cache old byte buffer so it does not get garbage collected in the event that it needs to be rolled (default = true)
logForceOnBufferRoll - Call force on the byte buffer in the event it needs to be rolled (default = false)
logForceOnClose - Call force on the byte buffer when the log is close (default = false)
logAsynchronousQueueCapacity - The capacity of the queue reponsible for transfering log messages between threads (default = 1024)
logAsynchronousConsumerPriority - The Java priority of the log consuming thread (default = 5)
logProcToBindConsumer - The core number to bind (thread pinning) the log consumer thread to (default = -1)