OnJava8-Examples/logging/PrintableLogRecord.java

61 lines
1.7 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// logging/PrintableLogRecord.java
2015-12-15 11:47:04 -08:00
// (c)2016 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
2015-06-15 17:47:35 -07:00
// Override LogRecord toString()
import java.util.logging.*;
2015-12-16 22:51:48 -08:00
public class PrintableLogRecord extends LogRecord {
public PrintableLogRecord(Level level, String str) {
2015-06-15 17:47:35 -07:00
super(level, str);
}
@Override
public String toString() {
String result = "Level<" + getLevel()+ ">\n"
+ "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++)
result += " Param # <" + i + " value "+
objParams[i].toString() + ">\n";
result += "ResourceBundle<"
+ getResourceBundle()
+ ">\nResourceBundleName<"
+ getResourceBundleName()
+ ">\nSequenceNumber<"
+ getSequenceNumber()
+ ">\nSourceClassName<"
+ getSourceClassName()
+ ">\nSourceMethodName<"
+ getSourceMethodName()
+ ">\nThread Id<" + getThreadID()
+ ">\nThrown<" + getThrown() + ">";
return result;
}
public static void main(String[] args) {
PrintableLogRecord logRecord =
new PrintableLogRecord(
Level.FINEST, "Simple Log Record");
System.out.println(logRecord);
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
Level<FINEST>
LoggerName<null>
Message<Simple Log Record>
2016-07-27 11:12:11 -06:00
CurrentMillis<1469638244376>
2015-06-15 17:47:35 -07:00
Params<null>
ResourceBundle<null>
ResourceBundleName<null>
SequenceNumber<0>
SourceClassName<null>
SourceMethodName<null>
Thread Id<1>
Thrown<null>
2015-09-07 11:44:36 -06:00
*/