OnJava8-Examples/logging/PrintableLogRecord.java

59 lines
1.5 KiB
Java
Raw Normal View History

2015-05-05 11:20:13 -07:00
//: logging/PrintableLogRecord.java
// Override LogRecord toString()
import java.util.logging.*;
2015-05-18 23:05:20 -07:00
public class
PrintableLogRecord extends LogRecord {
public
PrintableLogRecord(Level level, String str) {
2015-05-05 11:20:13 -07:00
super(level, str);
}
@Override
public String toString() {
2015-05-18 23:05:20 -07:00
String result = "Level<" + getLevel()+ ">\n"
2015-05-05 11:20:13 -07:00
+ "LoggerName<" + getLoggerName() + ">\n"
+ "Message<" + getMessage() + ">\n"
+ "CurrentMillis<" + getMillis() + ">\n"
+ "Params";
Object[] objParams = getParameters();
if(objParams == null)
result += "<null>\n";
else
for(int i = 0; i < objParams.length; i++)
2015-05-18 23:05:20 -07:00
result += " Param # <" + i + " value "+
2015-05-05 11:20:13 -07:00
objParams[i].toString() + ">\n";
2015-05-18 23:05:20 -07:00
result += "ResourceBundle<"
+ getResourceBundle()
+ ">\nResourceBundleName<"
+ getResourceBundleName()
+ ">\nSequenceNumber<"
+ getSequenceNumber()
+ ">\nSourceClassName<"
+ getSourceClassName()
+ ">\nSourceMethodName<"
+ getSourceMethodName()
2015-05-05 11:20:13 -07:00
+ ">\nThread Id<" + getThreadID()
+ ">\nThrown<" + getThrown() + ">";
return result;
}
public static void main(String[] args) {
2015-05-18 23:05:20 -07:00
PrintableLogRecord logRecord =
new PrintableLogRecord(
Level.FINEST, "Simple Log Record");
2015-05-05 11:20:13 -07:00
System.out.println(logRecord);
}
2015-05-18 23:05:20 -07:00
} /* Output:
Level<FINEST>
LoggerName<null>
Message<Simple Log Record>
CurrentMillis<1431539016784>
Params<null>
ResourceBundle<null>
ResourceBundleName<null>
SequenceNumber<0>
SourceClassName<null>
SourceMethodName<null>
Thread Id<1>
Thrown<null>
*///:~