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

The following examples show how to use ch.qos.logback.classic.spi.ILoggingEvent#getLoggerName() . 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: ClassNameAndLineNumberConverter.java    From ns4_frame with Apache License 2.0 5 votes vote down vote up
protected String getFullyQualifiedName(ILoggingEvent event) {
	StackTraceElement[] cda = event.getCallerData();
	if (cda != null && cda.length > 0) {
		String loggerName = event.getLoggerName();
		int index = loggerName.indexOf(LogConstants.SPLIT_CATEGORY);
		loggerName = index != -1 ? loggerName.substring(0, index) : loggerName;
		/*String className = cda[cda.length - 1].getClassName();*/
		return loggerName /*+ LogConstants.CONNECT_CATEGORY
				+ className.substring(className.lastIndexOf(".") + 1) + "."
				+ Integer.toString(cda[cda.length - 1].getLineNumber())*/;
	}
	return CallerData.NA;
}
 
Example 4
Source File: LoggerNameKeyingStrategy.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public byte[] createKey(ILoggingEvent e) {
    final String loggerName;
    if (e.getLoggerName() == null) {
        loggerName = "";
    } else {
        loggerName = e.getLoggerName();
    }
    return ByteBuffer.allocate(4).putInt(loggerName.hashCode()).array();
}
 
Example 5
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 6
Source File: LoggerFilter.java    From baleen with Apache License 2.0 5 votes vote down vote up
/**
 * Decide whether or not to deny the event based on the settings of this filter
 *
 * @param event The logging event to test
 */
@Override
public FilterReply decide(ILoggingEvent event) {
  if (Strings.isNullOrEmpty(event.getLoggerName())) {
    return FilterReply.DENY;
  }

  for (String name : loggerName) {
    FilterReply ret;
    if (name.endsWith("/0")) {
      String nullTerminatedLN = event.getLoggerName() + "/0";
      ret = nameMatches(nullTerminatedLN.equals(name));
    } else {
      ret = nameMatches(event.getLoggerName().startsWith(name));
    }

    ret = shouldReturn(ret);
    if (ret != null) {
      return ret;
    }
  }

  if (exclude) {
    return FilterReply.NEUTRAL;
  } else {
    return FilterReply.DENY;
  }
}
 
Example 7
Source File: RollbarAppender.java    From rollbar-java with MIT License 5 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
  if (event.getLoggerName() != null && event.getLoggerName().startsWith(PACKAGE_NAME)) {
    addWarn("Recursive logging");
    return;
  }

  IThrowableProxy throwableProxy = event.getThrowableProxy();
  ThrowableWrapper rollbarThrowableWrapper = buildRollbarThrowableWrapper(throwableProxy);
  Map<String, Object> custom = this.buildCustom(event);

  rollbar.log(rollbarThrowableWrapper, custom, event.getFormattedMessage(),
      Level.lookupByName(event.getLevel().levelStr), false);

}
 
Example 8
Source File: LoggerNameKeyingStrategy.java    From logback-kafka-appender with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] createKey(ILoggingEvent e) {
    final String loggerName;
    if (e.getLoggerName() == null) {
        loggerName = "";
    } else {
        loggerName = e.getLoggerName();
    }
    return ByteBuffer.allocate(4).putInt(loggerName.hashCode()).array();
}
 
Example 9
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;
}