Java Code Examples for ch.qos.logback.classic.spi.ILoggingEvent#getThreadName()

The following examples show how to use ch.qos.logback.classic.spi.ILoggingEvent#getThreadName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DingTalkAppender.java    From jframework with Apache License 2.0 6 votes vote down vote up
private String transformStackTrace(ILoggingEvent event) {
    String exception = "";
    IThrowableProxy throwableProxy =  event.getThrowableProxy();
    if (throwableProxy != null) {
        exception = ThrowableProxyUtil.asString(throwableProxy);
    }

    StackTraceElement[] callerData = event.getCallerData();
    StackTraceElement stackTraceElement = callerData[0];

    String time = DEFAULT_DATE_FORMAT.format(new Date(event.getTimeStamp()));
    String threadName = event.getThreadName();
    String level = event.getLevel().toString();
    String logger = event.getLoggerName();
    String msg = event.getFormattedMessage();
    String className = stackTraceElement.getClassName();
    String method = stackTraceElement.getMethodName();
    int lineNumber = stackTraceElement.getLineNumber();

    return String.format(FORMAT_MESSAGE, time, threadName, level, logger, className, method, lineNumber, exception, msg);
}
 
Example 2
Source File: LogFilter.java    From DimpleBlog with Apache License 2.0 6 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event) {
    StringBuilder exception = new StringBuilder();
    IThrowableProxy iThrowableProxy1 = event.getThrowableProxy();
    if (iThrowableProxy1 != null) {
        exception.append("<span class='excehtext'>" + iThrowableProxy1.getClassName() + " " + iThrowableProxy1.getMessage() + "</span></br>");
        for (int i = 0; i < iThrowableProxy1.getStackTraceElementProxyArray().length; i++) {
            exception.append("<span class='excetext'>" + iThrowableProxy1.getStackTraceElementProxyArray()[i].toString() + "</span></br>");
        }
    }
    LoggerMessage loggerMessage = new LoggerMessage(
            event.getMessage()
            , DateFormat.getDateTimeInstance().format(new Date(event.getTimeStamp())),
            event.getThreadName(),
            event.getLoggerName(),
            event.getLevel().levelStr,
            exception.toString(),
            ""
    );
    LoggerQueue.getInstance().push(loggerMessage);
    return FilterReply.ACCEPT;
}
 
Example 3
Source File: UKeFuAppender.java    From youkefu with Apache License 2.0 5 votes vote down vote up
@Override
public void append(ILoggingEvent event) {
	super.append(event);
	try {
		if(UKDataContext.getContext()!=null) {
			Log log = new Log(UKDataContext.SYSTEM_ORGI , null , event.getFormattedMessage() , event.getLevel().toString() , event.getThreadName());
			log.setClazz(event.getLoggerName()) ;
			if(event.getFormattedMessage()!=null && event.getFormattedMessage().length() < 255){
				log.setMemo(event.getFormattedMessage());
			}else{
				log.setMemo(event.getFormattedMessage().substring(0 ,255));
			}
			if(event.getThrowableProxy()!=null){
				log.setMsg(ThrowableProxyUtil.asString(event.getThrowableProxy()));
			}
			
			log.setMethod(event.getThreadName());
			log.setLogtype(event.getLevel().toString().equals(Level.ERROR.toString()) ? "1" : "0") ;
			log.setLogtime(String.valueOf(UKTools.dateFormate.format(new Date()))) ;
			/**
			 * 临时缓存
			 */
			UKDataContext.tempLogQueue.add(log) ;
		}
	} catch (Throwable sqle) {
		sqle.printStackTrace();
	}

}
 
Example 4
Source File: CloudwatchLogsLogbackAppender.java    From cloudwatchlogs-java-appender with Apache License 2.0 5 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    StringBuilder message = new StringBuilder(event.getFormattedMessage());
    IThrowableProxy throwableProxy = event.getThrowableProxy();
    while (throwableProxy != null) {
        message.append("\n").append(dump(throwableProxy));
        throwableProxy = throwableProxy.getCause();
        if (throwableProxy != null) {
            message.append("\nCaused by:");
        }
    }

    String account = event.getMDCPropertyMap().get(CloudwatchLogsMDCPropertyNames.ACCOUNT);
    String action = event.getMDCPropertyMap().get(CloudwatchLogsMDCPropertyNames.ACTION);
    String user = event.getMDCPropertyMap().get(CloudwatchLogsMDCPropertyNames.USER);
    String session = event.getMDCPropertyMap().get(CloudwatchLogsMDCPropertyNames.SESSION);
    String request = event.getMDCPropertyMap().get(CloudwatchLogsMDCPropertyNames.REQUEST);

    Marker marker = event.getMarker();
    String eventId = marker == null ? null : marker.getName();

    Map<String, String> customMdcAttributes = new HashMap<>();
    for (String key : config.getCustomMdcKeys()) {
        String value = event.getMDCPropertyMap().get(key);
        if (value != null) {
            customMdcAttributes.put(key, value);
        }
    }

    CloudwatchLogsLogEvent logEvent = new CloudwatchLogsLogEvent(event.getLevel().toString(), event.getLoggerName(),
            eventId, message.toString(), event.getTimeStamp(), event.getThreadName(), account, action, user,
            session, request, customMdcAttributes);
    while (!eventQueue.offer(logEvent)) {
        // Discard old logging messages while queue is full.
        eventQueue.poll();
        discardedCount.incrementAndGet();
    }
    processedCount.incrementAndGet();
}
 
Example 5
Source File: LogFilter.java    From ticket with GNU General Public License v3.0 4 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event) {
    LoggerMessage loggerMessage = new LoggerMessage(event.getMessage(), DateFormat.getDateTimeInstance().format(new Date(event.getTimeStamp())), event.getThreadName(), event.getLoggerName(), event.getLevel().levelStr);
    // LogUtil.push(loggerMessage.toString());
    return FilterReply.ACCEPT;
}