SelfLog { public static void errorWithTraceId(String log, Throwable e) { try { String timestamp = Timestamp.currentTime(); StringWriter sw = new StringWriter(4096); PrintWriter pw = new PrintWriter(sw, false); pw.append(timestamp).append(ERROR_PREFIX).append("[").append(TracerUtils.getTraceId()) .append("]").append(log).append(StringUtils.NEWLINE); e.printStackTrace(pw); pw.println(); pw.flush(); selfLogAppenderManager.append(sw.toString()); } catch (Throwable t) { t.printStackTrace(); } }  static void error(String log, Throwable e); static void errorWithTraceId(String log, Throwable e); static void error(String log); static void errorWithTraceId(String log, String traceId); static void errorWithTraceId(String log); static void warn(String log); static void info(String log); static void infoWithTraceId(String log); static void flush();  }
@Test public void testErrorWithTraceIdForLogE() throws Exception { SelfLog.errorWithTraceId("error Info ", "traceid"); TestUtil.waitForAsyncLog(); List<String> logs = FileUtils.readLines(tracerSelfLog()); assertTrue(!logs.isEmpty()); }
@Test public void testErrorWithTraceIdForLogErrorThrowable() throws Exception { SelfLog.errorWithTraceId("error Info ", new Throwable()); TestUtil.waitForAsyncLog(); List<String> logs = FileUtils.readLines(tracerSelfLog()); assertTrue(!logs.isEmpty()); }