当前位置: 首页>>代码示例>>Java>>正文


Java LogEvent.getThrown方法代码示例

本文整理汇总了Java中org.apache.logging.log4j.core.LogEvent.getThrown方法的典型用法代码示例。如果您正苦于以下问题:Java LogEvent.getThrown方法的具体用法?Java LogEvent.getThrown怎么用?Java LogEvent.getThrown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.logging.log4j.core.LogEvent的用法示例。


在下文中一共展示了LogEvent.getThrown方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: append

import org.apache.logging.log4j.core.LogEvent; //导入方法依赖的package包/类
@Override
public void append(LogEvent event) {
    List<LogItem> logItems = new ArrayList<LogItem>();
    LogItem item = new LogItem();
    logItems.add(item);
    item.SetTime((int) (event.getTimeMillis() / 1000));
    item.PushBack("time", this.dateFormat.format(new Date(event.getTimeMillis())));
    item.PushBack("level", event.getLevel().toString());
    item.PushBack("thread", event.getThreadName());

    StackTraceElement source = event.getSource();
    if (source == null && (!event.isIncludeLocation())) {
        event.setIncludeLocation(true);
        source = event.getSource();
        event.setIncludeLocation(false);
    }

    item.PushBack("location", source == null ? "Unknown(Unknown Source)" : source.toString());

    String message = event.getMessage().getFormattedMessage();
    Throwable throwable = event.getThrown();
    if (throwable != null) {
        for (String s : Throwables.toStringList(throwable)) {
            message += System.getProperty("line.separator") + s;
        }
    }

    item.PushBack("message", message);
    Map<String, String> properties = event.getContextMap();
    if (properties.size() > 0) {
        Object[] keys = properties.keySet().toArray();
        Arrays.sort(keys);
        for (int i = 0; i < keys.length; i++) {
            item.PushBack(keys[i].toString(), properties.get(keys[i].toString()));
        }
    }
    producer.send(this.projectName, this.logstore, this.topic, null, logItems, new LoghubAppenderCallback(LOGGER,
            this.projectName, this.logstore, this.topic, null, logItems));
}
 
开发者ID:aliyun,项目名称:aliyun-log-log4j2-appender,代码行数:40,代码来源:LoghubAppender.java

示例2: resolve

import org.apache.logging.log4j.core.LogEvent; //导入方法依赖的package包/类
@Override
public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) {
    final Throwable exception = logEvent.getThrown();
    if (!context.isStackTraceEnabled() || exception == null) {
        return null;
    }
    Throwable rootCause = Throwables.getRootCause(exception);
    final String exceptionStackTrace = Throwables.serializeStackTrace(rootCause);
    return new TextNode(exceptionStackTrace);
}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:11,代码来源:ExceptionRootCauseStackTraceResolver.java

示例3: resolve

import org.apache.logging.log4j.core.LogEvent; //导入方法依赖的package包/类
@Override
public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) {
    final Throwable exception = logEvent.getThrown();
    if (exception == null) {
        return null;
    }
    Throwable rootCause = Throwables.getRootCause(exception);
    final String rootCauseMessage = rootCause.getMessage();
    return new TextNode(rootCauseMessage);
}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:11,代码来源:ExceptionRootCauseMessageResolver.java

示例4: resolve

import org.apache.logging.log4j.core.LogEvent; //导入方法依赖的package包/类
@Override
public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) {
    Throwable exception = logEvent.getThrown();
    if (!context.isStackTraceEnabled() || exception == null) {
        return null;
    }
    String exceptionStackTrace = Throwables.serializeStackTrace(exception);
    return new TextNode(exceptionStackTrace);
}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:10,代码来源:ExceptionStackTraceResolver.java

示例5: resolve

import org.apache.logging.log4j.core.LogEvent; //导入方法依赖的package包/类
@Override
public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) {
    final Throwable exception = logEvent.getThrown();
    if (exception == null) {
        return null;
    }
    Throwable rootCause = Throwables.getRootCause(exception);
    final String rootCauseClassName = rootCause.getClass().getCanonicalName();
    return new TextNode(rootCauseClassName);
}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:11,代码来源:ExceptionRootCauseClassNameResolver.java

示例6: resolve

import org.apache.logging.log4j.core.LogEvent; //导入方法依赖的package包/类
@Override
public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) {
    Throwable exception = logEvent.getThrown();
    if (exception == null) {
        return null;
    }
    String exceptionMessage = exception.getMessage();
    return new TextNode(exceptionMessage);
}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:10,代码来源:ExceptionMessageResolver.java

示例7: resolve

import org.apache.logging.log4j.core.LogEvent; //导入方法依赖的package包/类
@Override
public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) {
    Throwable exception = logEvent.getThrown();
    if (exception == null) {
        return null;
    }
    String exceptionClassName = exception.getClass().getCanonicalName();
    return new TextNode(exceptionClassName);
}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:10,代码来源:ExceptionClassNameResolver.java

示例8: checkException

import org.apache.logging.log4j.core.LogEvent; //导入方法依赖的package包/类
private static void checkException(LogEvent logEvent, JsonNode rootNode) {
    Throwable thrown = logEvent.getThrown();
    if (thrown != null) {
        assertThat(point(rootNode, "exception_class").asText()).isEqualTo(thrown.getClass().getCanonicalName());
        assertThat(point(rootNode, "exception_message").asText()).isEqualTo(thrown.getMessage());
        String stackTrace = Throwables.serializeStackTrace(thrown);
        assertThat(point(rootNode, "stacktrace").asText()).isEqualTo(stackTrace);
    }
}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:10,代码来源:LogstashLayoutTest.java

示例9: toSerializable

import org.apache.logging.log4j.core.LogEvent; //导入方法依赖的package包/类
public String toSerializable(LogEvent event) {
	StringBuilder builder = new StringBuilder();
	
       builder.append(OBJ_S);
       addField(builder,"@timestamp",ISO_DATETIME_TIME_ZONE_FORMAT_WITH_MILLIS.format(event.getTimeMillis()));
       
       if(event!=null){
        addField(builder,"logger_name", event.getLoggerName());
        
        if(event.getLevel()!=null){
        	addField(builder,"level", event.getLevel().name());
        	addField(builder,"level_int", event.getLevel().intLevel());
        }
        
        addField(builder,"thread_name", event.getThreadName());
        addField(builder,"source_host", getHostName());
        addField(builder,"source_ip", getHostIP());
        
        if(event.getMessage()!=null){
        	addField(builder,"message", event.getMessage().getFormattedMessage());
        }
        
        if (event.getThrown() !=null){
        	addField(builder,"exception",event.getThrown());
        }
        
        if (locationInfo) {
        	 addField(builder,"file",event.getSource().getFileName());
        	 addField(builder,"line_number",event.getSource().getLineNumber());
        	 addField(builder,"class",event.getSource().getClassName());
        	 addField(builder,"method",event.getSource().getMethodName());
        }
        
        if(event.getContextStack()!=null) {
        	addField(builder,"contextStack",event.getContextStack());
        }
        
        if(event.getContextMap()!=null) {
        	if(plainContextMap){
        		for(Entry<String,String> entry: event.getContextMap().entrySet()){
        			addField(builder,entry.getKey(),entry.getValue());
        		}
        	}else{
        		addField(builder,"contextMap",event.getContextMap());
        	}
        }
        
        if(userFields!=null){
        	for(UserField userField : userFields){
        		addField(builder,userField.getKey(),userField.getValue());
        	}
        }
       }
       addField(builder,"@version",VERSION,false);
       builder.append(OBJ_E);
       builder.append("\n");
	return builder.toString();
}
 
开发者ID:dubasdey,项目名称:log4j2-jsonevent-layout,代码行数:59,代码来源:JSONLog4j2Layout.java


注:本文中的org.apache.logging.log4j.core.LogEvent.getThrown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。