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

The following examples show how to use ch.qos.logback.classic.spi.ILoggingEvent#getLevel() . 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: LogbackColor.java    From litchi with Apache License 2.0 6 votes vote down vote up
@Override
protected String getForegroundColorCode(ILoggingEvent event) {
    Level level = event.getLevel();
    switch (level.toInt()) {
        case Level.ERROR_INT:
            return ANSIConstants.RED_FG;
        case Level.WARN_INT:
            return ANSIConstants.YELLOW_FG;
        case Level.INFO_INT:
            return ANSIConstants.BLUE_FG;
        case Level.DEBUG_INT:
            return ANSIConstants.GREEN_FG;
        default:
            return ANSIConstants.DEFAULT_FG;
    }
}
 
Example 2
Source File: LevelRangeFilter.java    From logging-java with Apache License 2.0 6 votes vote down vote up
@Override
public FilterReply decide(final ILoggingEvent event) {
  if (!isStarted()) {
    return FilterReply.NEUTRAL;
  }

  if (levelMin != null && event.getLevel().levelInt < levelMin.levelInt) {
    return FilterReply.DENY;
  }

  if (levelMax != null && event.getLevel().levelInt > levelMax.levelInt) {
    return FilterReply.DENY;
  }

  return FilterReply.NEUTRAL;
}
 
Example 3
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 4
Source File: CollectorLogbackAppender.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    if (inFlush.get()) {
        return;
    }
    if (event.getLevel() == Level.DEBUG && event.getLoggerName().startsWith("io.grpc.")) {
        return;
    }
    if (event.getLoggerName().startsWith("org.glowroot.central.")
            || event.getLoggerName().startsWith("org.glowroot.ui.")) {
        // this can happen during integration tests when agent and the central collector are
        // running in the same JVM (using LocalContainer for agent)
        return;
    }
    LogEvent.Builder builder = LogEvent.newBuilder()
            .setTimestamp(event.getTimeStamp())
            .setLevel(toProto(event.getLevel()))
            .setLoggerName(event.getLoggerName())
            .setMessage(event.getFormattedMessage());
    IThrowableProxy throwable = event.getThrowableProxy();
    if (throwable != null) {
        builder.setThrowable(toProto(throwable));
    }
    flush(builder.build());
}
 
Example 5
Source File: JobMessageLogAppender.java    From edison-microservice with Apache License 2.0 6 votes vote down vote up
@Override
protected void append(final ILoggingEvent eventObject) {
    Map<String, String> mdcMap = eventObject.getMDCPropertyMap();
    // TODO: check for JOB marker:
    if (mdcMap.containsKey("job_id") && eventObject.getMarker() != null && JobMarker.JOB.contains(eventObject.getMarker())) {
        String jobId = mdcMap.get("job_id");
        Level level = eventObject.getLevel();
        de.otto.edison.jobs.domain.Level edisonLevel = logLevelToEdisonLevel(level);

        String message = eventObject.getFormattedMessage();

        try {
            final JobMessage jobMessage = jobMessage(edisonLevel, message, OffsetDateTime.now());
            jobService.appendMessage(jobId, jobMessage);
        }
        catch(final RuntimeException e) {
            addError("Failed to persist job message (jobId=" + jobId + "): " + message, e);
        }
    }
}
 
Example 6
Source File: ErrorStatisticsAppender.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    if (event == null) {
        return;
    }
    if (event.getLevel() == Level.ERROR || event.getLevel() == Level.WARN) {
        IThrowableProxy throwableProxy = event.getThrowableProxy();
        if (throwableProxy != null) {
        	//接口名
            String errorClassName = throwableProxy.getClassName();
            if (errorClassName != null && !"".equals(errorClassName.trim())) {
            	//写入AtomicLongMap并计数
                ERROR_NAME_VALUE_MAP.getAndIncrement(errorClassName);
            }
        }
    }
}
 
Example 7
Source File: SLF4JLoggerIT.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public void append(ILoggingEvent event)
{
  // Assign the log message and it's level to the outer class instance
  // variables so that it can see the messages logged
  lastLogMessage = event.getFormattedMessage();
  lastLogMessageLevel = event.getLevel();
}
 
Example 8
Source File: GuiAppender.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
protected boolean isIgnoringLogRecord(ILoggingEvent event) {
  if (event.getLevel().levelInt < Level.INFO.levelInt) {
    if (event.hasCallerData()
      && event.getCallerData().length > 0) {
      for (String ignoreClass : ignoreClassesList) {
        if (StringUtils.equals(ignoreClass, event.getCallerData()[0].getClassName())) {
          return true;
        }
      }
    }
  }

  return false;
}
 
Example 9
Source File: MinMaxFilter.java    From baleen with Apache License 2.0 5 votes vote down vote up
/**
 * Decide whether a given logging event should be accepted or not by this filter (i.e. whether it
 * falls within the specified levels).
 *
 * @param event The logging event being examined
 * @return Whether the event should be accepted or not
 */
@Override
public FilterReply decide(ILoggingEvent event) {
  Level level = event.getLevel();

  if (level == null) {
    // We specifically avoid logging here to avoid any circular issues.
    return FilterReply.DENY;
  }

  boolean allow = level.isGreaterOrEqual(min) && max.isGreaterOrEqual(level);

  return allow ? FilterReply.NEUTRAL : FilterReply.DENY;
}
 
Example 10
Source File: MetricsLogAppender.java    From pravega with Apache License 2.0 5 votes vote down vote up
@Override
public void doAppend(ILoggingEvent event) throws LogbackException {
    if (event.getLevel() == Level.ERROR) {
        recordEvent(MetricsNames.LOG_ERRORS, event);
    } else if (event.getLevel() == Level.WARN) {
        recordEvent(MetricsNames.LOG_WARNINGS, event);
    }
}
 
Example 11
Source File: LogbackFilter.java    From talent-aio with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event)
{
	int xx = event.getLevel().levelInt;
	int xx1 = Level.ERROR.toInt();  //error:40000, warn:30000, info:20000
	if (xx >= xx1)
	{
		JFrameMain.getInstance().getMsgTextArea().append(event.getFormattedMessage() + System.lineSeparator());
	}
	return FilterReply.ACCEPT;
}
 
Example 12
Source File: LogCollector.java    From jadx with Apache License 2.0 5 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
	synchronized (this) {
		Level level = event.getLevel();
		String msg = layout.doLayout(event);
		store(level, msg);
		if (listener != null && level.isGreaterOrEqual(listener.getFilterLevel())) {
			listener.onAppend(msg);
		}
	}
}
 
Example 13
Source File: ProviderBinderTest.java    From everrest with Eclipse Public License 2.0 5 votes vote down vote up
private void assertThatErrorLoggingEventWithThrowableAppended(Class<? extends Throwable> throwable) {
    for (ILoggingEvent loggingEvent : retrieveLoggingEvents()) {
        if (loggingEvent.getLevel() == Level.ERROR
            && loggingEvent.getThrowableProxy() != null
            && loggingEvent.getThrowableProxy().getClassName().equals(throwable.getName())) {
            return;
        }
    }
    fail(String.format("Error event with error type %s was not logged", throwable.getName()));
}
 
Example 14
Source File: ErrorCatcher.java    From FlareBot with MIT License 5 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event) {
    String msg = event.getFormattedMessage();
    if (msg == null)
        msg = "null";
    if (event.getMarker() != Markers.NO_ANNOUNCE
            && FlareBot.instance() != null
            && event.getLevel() == Level.ERROR || event.getLevel() == Level.WARN) {
        String finalMsg = msg;
        if (event.getThreadName().startsWith("lava-daemon-pool")) {
            return FilterReply.NEUTRAL;
        }
        EXECUTOR.submit(() -> {
            Throwable throwable = null;
            if (event.getThrowableProxy() != null && event.getThrowableProxy() instanceof ThrowableProxy) {
                throwable = ((ThrowableProxy) event.getThrowableProxy()).getThrowable();
            }
            if (event.getLevel() == Level.WARN) {
                // Warnings should not have a throwable!
                MessageUtils.sendWarningMessage(finalMsg, Constants.getErrorLogChannel());
                return;
            }
            if (throwable != null) {
                if (event.getMarker() == Markers.TAG_DEVELOPER)
                    MessageUtils.sendFatalException(finalMsg, throwable, Constants.getErrorLogChannel());
                else
                    MessageUtils.sendException(finalMsg, throwable, Constants.getErrorLogChannel());
            } else {
                if (event.getMarker() == Markers.TAG_DEVELOPER)
                    MessageUtils.sendFatalErrorMessage(finalMsg, Constants.getErrorLogChannel());
                else
                    MessageUtils.sendErrorMessage(finalMsg, Constants.getErrorLogChannel());
            }
        });
    }
    return FilterReply.NEUTRAL;
}
 
Example 15
Source File: ConsoleLogAppender.java    From xJavaFxTool-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected void append(ILoggingEvent eventObject) {
    if (eventObject.getLevel() == Level.ERROR) {
        try {
            TooltipUtil.showToast("发生错误:\n" + eventObject.getFormattedMessage());
        } catch (Exception e) {

        }
    }
    super.append(eventObject);
}
 
Example 16
Source File: DingTalkAppender.java    From jframework with Apache License 2.0 5 votes vote down vote up
@Override
public void append(ILoggingEvent event) {
    if (event.getLevel() != Level.ERROR) {
        return;
    }

    String msg = transformStackTrace(event);
    DingTalkUtil.send(msg, event.getLoggerName(), Stream.of(to).collect(Collectors.toSet()));
}
 
Example 17
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;
}
 
Example 18
Source File: ViewAppender.java    From libreveris with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void publish (ILoggingEvent event)
{
    Level level = event.getLevel();
    view.publishMessage(level, event.getFormattedMessage());
}
 
Example 19
Source File: DisruptorLogAppender.java    From NettyFileTransfer with Apache License 2.0 2 votes vote down vote up
/**
 * Events of level TRACE, DEBUG and INFO are deemed to be discardable.
 * 
 * @param event
 * @return true if the event is of level TRACE, DEBUG or INFO false
 *         otherwise.
 */
protected boolean isDiscardable(ILoggingEvent event) {
	Level level = event.getLevel();
	return level.toInt() <= Level.INFO_INT;
}
 
Example 20
Source File: DisruptorLogAppender.java    From High-concurrent-server with Apache License 2.0 2 votes vote down vote up
/**
 * Events of level TRACE, DEBUG and INFO are deemed to be discardable.
 * 
 * @param event
 * @return true if the event is of level TRACE, DEBUG or INFO false
 *         otherwise.
 */
protected boolean isDiscardable(ILoggingEvent event) {
	Level level = event.getLevel();
	return level.toInt() <= Level.INFO_INT;
}