LogbackUtil { public static void addCallerData(ILoggingEvent ev, LogDataBuilder builder) { if (ev.hasCallerData()) { final StackTraceElement[] callerData = ev.getCallerData(); if (callerData.length > 0) { final StackTraceElement stackTraceElement = callerData[0]; builder.withClass(stackTraceElement.getClassName()); builder.withMethod(stackTraceElement.getMethodName()); builder.withLineNumber(Integer.toString(stackTraceElement.getLineNumber())); } } }  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 testAddCallerData() throws Exception { final StackTraceElement[] stackTrace = new Throwable().getStackTrace(); final ILoggingEvent mock = mock(ILoggingEvent.class); when(mock.hasCallerData()).thenReturn(true); when(mock.getCallerData()).thenReturn(stackTrace); LogbackUtil.addCallerData(mock, builder); assertEquals(builder.build().getMethod(), "testAddCallerData"); assertEquals(builder.build().getClazz(),getClass().getName()); }
@Test public void testAddCallerDataWithoutData() throws Exception { final StackTraceElement[] stackTrace = new Exception("Some exception").getStackTrace(); final ILoggingEvent mock = mock(ILoggingEvent.class); when(mock.hasCallerData()).thenReturn(false); LogbackUtil.addCallerData(mock, builder); assertEquals(builder.build().getMethod(), ""); assertEquals(builder.build().getClazz(),""); }