本文整理汇总了Java中ch.qos.logback.classic.spi.LoggingEvent.setCallerData方法的典型用法代码示例。如果您正苦于以下问题:Java LoggingEvent.setCallerData方法的具体用法?Java LoggingEvent.setCallerData怎么用?Java LoggingEvent.setCallerData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.classic.spi.LoggingEvent
的用法示例。
在下文中一共展示了LoggingEvent.setCallerData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTranslate
import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@Test
public void testTranslate() throws Exception {
//Given
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)});
//when
final LogData logData = LogbackUtil.translate(le).build();
//then
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);
}
示例2: logEvent
import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
private static void logEvent(Ehcache cache, Element elem, CacheEventType eventType) {
int cacheApproxSize = -1;
if (cache.getStatus() == Status.STATUS_ALIVE) {
try {
cacheApproxSize = cache.getSize();
} catch (CacheException | IllegalStateException ignored) {
}
}
LoggingEvent loggingEvent = new LoggingEvent(Logger.FQCN, LOGGER, Level.TRACE,
String.format(MSG_FORMAT, cache.getName(), cache.getStatus(), cacheApproxSize, elem.getObjectKey(), eventType.getId()), null, null);
StackTraceElement[] stackFrames = new Throwable().getStackTrace();
for (int a = 1; a < stackFrames.length; a++) {
if (!STACK_SKIP_CLASS_NAMES.contains(stackFrames[a].getClassName())) {
stackFrames = ArrayUtils.subarray(stackFrames, a, stackFrames.length);
break;
}
}
loggingEvent.setCallerData(stackFrames);
LOGGER.callAppenders(loggingEvent);
}
示例3: report
import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
public void report(SdcctIssueSeverity severity, String msg, SdcctLocation loc, @Nullable Throwable cause) {
LoggingEvent event = new LoggingEvent(Logger.FQCN, LOGGER, SEVERITY_LEVELS.get(severity), msg, cause, null);
StackTraceElement[] stackFrames = new Throwable().getStackTrace();
for (int a = 1; a < stackFrames.length; a++) {
if (!STACK_SKIP_CLASS_NAMES.contains(stackFrames[a].getClassName())) {
stackFrames = ArrayUtils.subarray(stackFrames, a, stackFrames.length);
break;
}
}
event.setCallerData(stackFrames);
LOGGER.callAppenders(event);
}
示例4: log
import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
public void log(Level level, @Nullable String msg, @Nullable Throwable cause) {
LoggingEvent event = new LoggingEvent(ch.qos.logback.classic.Logger.FQCN, LOGGER, level, msg, cause, null);
StackTraceElement[] stackFrames = new Throwable().getStackTrace();
for (int a = 1; a < stackFrames.length; a++) {
if (!STACK_SKIP_CLASS_NAMES.contains(stackFrames[a].getClassName())) {
stackFrames = ArrayUtils.subarray(stackFrames, a, stackFrames.length);
break;
}
}
event.setCallerData(stackFrames);
LOGGER.callAppenders(event);
}
示例5: createLoggingEvent
import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
private LoggingEvent createLoggingEvent() {
LoggingEvent event = new LoggingEvent("com.example.XMLLayoutTest-<&>'\"]]>", root,
Level.DEBUG, MESSAGE,
new RuntimeException("Dummy exception: <&>'\"]]>"), null);
event.setThreadName("Dummy thread <&>'\"");
event.getMDCPropertyMap().put(MDC_KEY, MDC_VALUE);
StackTraceElement ste1 = new StackTraceElement("c1", "m1", "f1", 1);
StackTraceElement ste2 = new StackTraceElement("c2", "m2", "f2", 2);
event.setCallerData(new StackTraceElement[]{ ste1, ste2} );
return event;
}
示例6: emptyCallerDataShouldBeHandledGracefully
import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@Test
public void emptyCallerDataShouldBeHandledGracefully() {
LoggingEvent event = createLoggingEvent();
event.setCallerData(new StackTraceElement[0]);
appender.append(event);
event.setCallerData(new StackTraceElement[] {null});
appender.append(event);
checker.assertIsErrorFree();
}
示例7: newEvent
import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
protected Object newEvent(LogDetails logDetails) {
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(logDetails.getClassName());
LoggingEvent event = new LoggingEvent(this.getClass().getName(), logger, Level.DEBUG, logDetails.getLogMessage(),
logDetails.getException(), null);
event.setThreadName(logDetails.getThreadName());
event.setTimeStamp(logDetails.getTimeMillis());
event.setMDCPropertyMap(logDetails.getMdc());
StackTraceElement callerData = new StackTraceElement(logDetails.getClassName(), logDetails.getMethodName(),
logDetails.getFileName(), logDetails.getLineNumber());
event.setCallerData(new StackTraceElement[] { callerData });
return event;
}