### Question:
Log4Json extends Layout { public String toJson(LoggingEvent event) throws IOException { StringWriter writer = new StringWriter(); toJson(writer, event); return writer.toString(); } Log4Json(); @Override String getContentType(); @Override String format(LoggingEvent event); String toJson(LoggingEvent event); Writer toJson(final Writer writer, final LoggingEvent event); Writer toJson(final Writer writer,
                       final String loggerName,
                       final long timeStamp,
                       final String level,
                       final String threadName,
                       final String message,
                       final ThrowableInformation ti); @Override boolean ignoresThrowable(); @Override void activateOptions(); static ContainerNode parse(String json); static final String DATE; static final String EXCEPTION_CLASS; static final String LEVEL; static final String MESSAGE; static final String NAME; static final String STACK; static final String THREAD; static final String TIME; static final String JSON_TYPE; }### Answer:
@Test public void testConstruction() throws Throwable { Log4Json l4j = new Log4Json(); String outcome = l4j.toJson(new StringWriter(), "name", 0, "DEBUG", "thread1", "hello, world", null).toString(); println("testConstruction", outcome); }
@Test public void testException() throws Throwable { Exception e = new NoRouteToHostException("that box caught fire 3 years ago"); ThrowableInformation ti = new ThrowableInformation(e); Log4Json l4j = new Log4Json(); long timeStamp = Time.now(); String outcome = l4j.toJson(new StringWriter(), "testException", timeStamp, "INFO", "quoted\"", "new line\n and {}", ti) .toString(); println("testException", outcome); }