Introduction
JavaLog output can be controlled by a single format string. This
string is reminiscent of the format string a C printf statement. The
default format string prints the log events as a single line of text.
However, this can be changed to produce almost any format and spread
the log event over many lines.
Default format string
The following is a portion of the output produced by the test program
main of grace.log.Log. This sample output has been modified slightly
(with '\' characters) to appear prettier in browsers. It uses the
default format for producing output to the standard out. This format
is:
"%t(%r):%n: %e: %h: %c.%f:%l%(: %m)m%(: %j)o\n\n"
Output:
$ java grace.log.Log
...
03/01/99 14:06:46(0.479):19: trace: system.main.Test-Thread.1: Log$Test.logSomeMessages:1196: \
Example of trace(message, object): Vector ={String [0]="Value1"; String [1]="Value2";}
03/01/99 14:06:46(0.485):20: trace: system.main.Test-Thread.1: Log$Test.logSomeMessages:1198: \
Another Example of trace(message, object): grace.log.Log$Test = \
{Integer i=123; Double d=123.45; String s="a sample string"; \
Object nullString=null; Vector v={String [0]="Value1"; String [1]="Value2";}}
03/01/99 14:06:46(0.507):21: warning: system.main.Test-Thread.1: Log$Test.logSomeMessages:1201: Example of warning(message)
03/01/99 14:06:46(0.512):22: error: system.main.Test-Thread.1: Log$Test.logSomeMessages:1202: Example of error(message)
03/01/99 14:06:46(0.516):23: error: system.main.Test-Thread.1: Log$Test.testThrowFunction:1151: \
java.io.IOException: Exception message: java.io.IOException: Exception message
at grace.log.Log$Test.testThrowFunction(Log.java:1151)
at grace.log.Log$Test.logSomeMessages(Log.java:1204)
at grace.log.Log$1.run(Log.java:1164)
Custom format string
Here's another style of output produced from the same program but with
a different formatting string. It was run like this:
$ java -Dlog.format="time:\t\t%t\nseq:\t\t%n\ntype:\t\t%e\nthread:\t\tt%h\nposition:\t%c.%f\nline:\t\t%l\nmessage:\t%m\nobject:\t\t%o\n\n" \
-Dlog.exception.format="%c: %m" -Dlog.object.format="%J" grace.log.Log
...
time: 03/01/99 15:14:19
seq: 19
type: trace
thread: tsystem.main.Test-Thread.1
position: Log$Test.logSomeMessages
line: 1196
message: Example of trace(message, object)
object: Vector = {
String [0] = "Value1";
String [1] = "Value2";
}
time: 03/01/99 15:14:19
seq: 20
type: trace
thread: tsystem.main.Test-Thread.1
position: Log$Test.logSomeMessages
line: 1198
message: Another Example of trace(message, object)
object: grace.log.Log$Test = {
Integer i = 123;
Double d = 123.45;
String s = "a sample string";
Object nullString = null;
Vector v = {
String [0] = "Value1";
String [1] = "Value2";
}
}
time: 03/01/99 15:14:19
seq: 21
type: warning
thread: tsystem.main.Test-Thread.1
position: Log$Test.logSomeMessages
line: 1201
message: Example of warning(message)
object:
time: 03/01/99 15:14:19
seq: 22
type: error
thread: tsystem.main.Test-Thread.1
position: Log$Test.logSomeMessages
line: 1202
message: Example of error(message)
object:
time: 03/01/99 15:14:19
seq: 23
type: error
thread: tsystem.main.Test-Thread.1
position: Log$Test.testThrowFunction
line: 1151
message:
object: java.io.IOException: Exception message