LogbackUtil { public static LogDataBuilder translate(ILoggingEvent ev) { final LogDataBuilder builder = new LogDataBuilder() .withLoggerName(ev.getLoggerName()) .withMessage(ev.getFormattedMessage()) .withLevel(convertLevel(ev.getLevel())) .withProperties(ev.getMDCPropertyMap()) .withDate(new Date(ev.getTimeStamp())) .withThread(ev.getThreadName()); addMarker(ev.getMarker(), ev.getMDCPropertyMap(), builder); addException(ev.getThrowableProxy(), ev.getMessage(), builder); addCallerData(ev, builder); return builder; }  static LogDataBuilder translate(ILoggingEvent ev); static void addCallerData(ILoggingEvent ev, LogDataBuilder builder); static void addException(IThrowableProxy throwableProxy, String message, LogDataBuilder builder); static void addMarker(Marker marker, Map<String, String> mdcMap, LogDataBuilder builder); static Level convertLevel(ch.qos.logback.classic.Level level);  }
@Test public void testTranslate() throws Exception { LoggerContext context = new LoggerContext(); Logger logger = context.getLogger("SomeLogger"); LoggingEvent le = new LoggingEvent("a.b.C",logger, ch.qos.logback.classic.Level.INFO,"message",null,null); final Map<String, String> split = Splitter.on(",").withKeyValueSeparator("=").split("a=b,b=as"); le.setMDCPropertyMap(split); le.setCallerData(new StackTraceElement[]{new StackTraceElement("a.b.C","someMethod","C.java",120)}); final LogData logData = LogbackUtil.translate(le).build(); assertEquals(logData.getMessage(),"message"); assertEquals(logData.getLevel(),Level.INFO); assertEquals(logData.getLoggerName(),"SomeLogger"); assertEquals(logData.getClazz(),"a.b.C"); assertEquals(logData.getMethod(),"someMethod"); assertEquals(logData.getLine(),"120"); assertEquals(logData.getProperties(),split); }