|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.log4j.Layout
org.apache.hadoop.log.Log4Json
public class Log4Json
This offers a log layout for JSON, with some test entry points. It's purpose is to allow Log4J to generate events that are easy for other programs to parse, but which are somewhat human-readable. Some features.
{"name":"test","time":1318429136789,"date":"2011-10-12 15:18:56,789","level":"INFO","thread":"main","message":"test message"}An event with an error will contain data similar to that below (which has been reformatted to be multi-line).
{ "name":"testException", "time":1318429136789, "date":"2011-10-12 15:18:56,789", "level":"INFO", "thread":"quoted\"", "message":"new line\n and {}", "exceptionclass":"java.net.NoRouteToHostException", "stack":[ "java.net.NoRouteToHostException: that box caught fire 3 years ago", "\tat org.apache.hadoop.log.TestLog4Json.testException(TestLog4Json.java:49)", "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)", "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)", "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)", "\tat java.lang.reflect.Method.invoke(Method.java:597)", "\tat junit.framework.TestCase.runTest(TestCase.java:168)", "\tat junit.framework.TestCase.runBare(TestCase.java:134)", "\tat junit.framework.TestResult$1.protect(TestResult.java:110)", "\tat junit.framework.TestResult.runProtected(TestResult.java:128)", "\tat junit.framework.TestResult.run(TestResult.java:113)", "\tat junit.framework.TestCase.run(TestCase.java:124)", "\tat junit.framework.TestSuite.runTest(TestSuite.java:232)", "\tat junit.framework.TestSuite.run(TestSuite.java:227)", "\tat org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)", "\tat org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)", "\tat org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:120)", "\tat org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:145)", "\tat org.apache.maven.surefire.Surefire.run(Surefire.java:104)", "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)", "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)", "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)", "\tat java.lang.reflect.Method.invoke(Method.java:597)", "\tat org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)", "\tat org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1017)" ] }
Field Summary | |
---|---|
static String |
DATE
|
static String |
EXCEPTION_CLASS
|
static String |
JSON_TYPE
|
static String |
LEVEL
|
static String |
MESSAGE
|
static String |
NAME
|
static String |
STACK
|
static String |
THREAD
|
static String |
TIME
|
Fields inherited from class org.apache.log4j.Layout |
---|
LINE_SEP, LINE_SEP_LEN |
Constructor Summary | |
---|---|
Log4Json()
|
Method Summary | |
---|---|
void |
activateOptions()
Do nothing |
String |
format(org.apache.log4j.spi.LoggingEvent event)
|
String |
getContentType()
|
boolean |
ignoresThrowable()
This appender does not ignore throwables |
static org.codehaus.jackson.node.ContainerNode |
parse(String json)
For use in tests |
String |
toJson(org.apache.log4j.spi.LoggingEvent event)
Convert an event to JSON |
Writer |
toJson(Writer writer,
org.apache.log4j.spi.LoggingEvent event)
Convert an event to JSON |
Writer |
toJson(Writer writer,
String loggerName,
long timeStamp,
String level,
String threadName,
String message,
org.apache.log4j.spi.ThrowableInformation ti)
Build a JSON entry from the parameters. |
Methods inherited from class org.apache.log4j.Layout |
---|
getFooter, getHeader |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DATE
public static final String EXCEPTION_CLASS
public static final String LEVEL
public static final String MESSAGE
public static final String NAME
public static final String STACK
public static final String THREAD
public static final String TIME
public static final String JSON_TYPE
Constructor Detail |
---|
public Log4Json()
Method Detail |
---|
public String getContentType()
getContentType
in class org.apache.log4j.Layout
public String format(org.apache.log4j.spi.LoggingEvent event)
format
in class org.apache.log4j.Layout
public String toJson(org.apache.log4j.spi.LoggingEvent event) throws IOException
event
- the event -must not be null
IOException
- on problems generating the JSONpublic Writer toJson(Writer writer, org.apache.log4j.spi.LoggingEvent event) throws IOException
writer
- the destination writerevent
- the event -must not be null
IOException
- on problems generating the JSONpublic Writer toJson(Writer writer, String loggerName, long timeStamp, String level, String threadName, String message, org.apache.log4j.spi.ThrowableInformation ti) throws IOException
writer
- destinationloggerName
- logger nametimeStamp
- time_t valuelevel
- level stringthreadName
- name of the threadmessage
- rendered messageti
- nullable thrown information
IOException
- on any problempublic boolean ignoresThrowable()
ignoresThrowable
in class org.apache.log4j.Layout
public void activateOptions()
public static org.codehaus.jackson.node.ContainerNode parse(String json) throws IOException
json
- incoming JSON to parse
IOException
- on any parsing problems
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |