Java Code Examples for org.apache.logging.log4j.core.LogEvent#getLevel()
The following examples show how to use
org.apache.logging.log4j.core.LogEvent#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: HighlightErrorConverter.java From TerminalConsoleAppender with MIT License | 6 votes |
@Override public void format(LogEvent event, StringBuilder toAppendTo) { if (TerminalConsoleAppender.isAnsiSupported()) { Level level = event.getLevel(); if (level.isMoreSpecificThan(Level.ERROR)) { format(ANSI_ERROR, event, toAppendTo); return; } else if (level.isMoreSpecificThan(Level.WARN)) { format(ANSI_WARN, event, toAppendTo); return; } } //noinspection ForLoopReplaceableByForEach for (int i = 0, size = formatters.size(); i < size; i++) { formatters.get(i).format(event, toAppendTo); } }
Example 2
Source File: CatAppender4Log4j2.java From x-pipe with Apache License 2.0 | 6 votes |
@Override public void append(LogEvent event) { MessageManager messageManager = Cat.getManager(); boolean isTraceMode = false; if(messageManager != null){ isTraceMode = messageManager.isTraceMode(); } Level level = event.getLevel(); if (level.isMoreSpecificThan(Level.ERROR)) { logError(event); } else if (isTraceMode) { logTrace(event); } }
Example 3
Source File: MixinPlatformAgentFMLLegacy.java From Mixin with MIT License | 6 votes |
@Override public void append(LogEvent event) { if (event.getLevel() != Level.DEBUG || !"Validating minecraft".equals(event.getMessage().getFormattedMessage())) { return; } // transition to INIT this.delegate.accept(Phase.INIT); // Only reset the log level if it's still ALL. If something // else changed the log level after we did, we don't want // overwrite that change. No null check is needed here // because the appender will not be injected if the log is // null if (MixinPlatformAgentFMLLegacy.log.getLevel() == Level.ALL) { MixinPlatformAgentFMLLegacy.log.setLevel(MixinPlatformAgentFMLLegacy.oldLevel); } }
Example 4
Source File: Log4jLogEvent.java From logging-log4j2 with Apache License 2.0 | 6 votes |
public LogEventProxy(final LogEvent event, final boolean includeLocation) { this.loggerFQCN = event.getLoggerFqcn(); this.marker = event.getMarker(); this.level = event.getLevel(); this.loggerName = event.getLoggerName(); final Message temp = event.getMessage(); message = temp instanceof ReusableMessage ? memento((ReusableMessage) temp) : temp; this.timeMillis = event.getInstant().getEpochMillisecond(); this.nanoOfMillisecond = event.getInstant().getNanoOfMillisecond(); this.thrown = event.getThrown(); this.thrownProxy = event.getThrownProxy(); this.contextData = memento(event.getContextData()); this.contextStack = event.getContextStack(); this.source = includeLocation ? event.getSource() : null; this.threadId = event.getThreadId(); this.threadName = event.getThreadName(); this.threadPriority = event.getThreadPriority(); this.isLocationRequired = includeLocation; this.isEndOfBatch = event.isEndOfBatch(); this.nanoTime = event.getNanoTime(); }
Example 5
Source File: MutableLogEvent.java From logging-log4j2 with Apache License 2.0 | 6 votes |
/** * Initialize the fields of this {@code MutableLogEvent} from another event. * Similar in purpose and usage as {@link org.apache.logging.log4j.core.impl.Log4jLogEvent.LogEventProxy}, * but a mutable version. * <p> * This method is used on async logger ringbuffer slots holding MutableLogEvent objects in each slot. * </p> * * @param event the event to copy data from */ public void initFrom(final LogEvent event) { this.loggerFqcn = event.getLoggerFqcn(); this.marker = event.getMarker(); this.level = event.getLevel(); this.loggerName = event.getLoggerName(); this.thrown = event.getThrown(); this.thrownProxy = event.getThrownProxy(); this.instant.initFrom(event.getInstant()); // NOTE: this ringbuffer event SHOULD NOT keep a reference to the specified // thread-local MutableLogEvent's context data, because then two threads would call // ReadOnlyStringMap.clear() on the same shared instance, resulting in data corruption. this.contextData.putAll(event.getContextData()); this.contextStack = event.getContextStack(); this.source = event.isIncludeLocation() ? event.getSource() : null; this.threadId = event.getThreadId(); this.threadName = event.getThreadName(); this.threadPriority = event.getThreadPriority(); this.endOfBatch = event.isEndOfBatch(); this.includeLocation = event.isIncludeLocation(); this.nanoTime = event.getNanoTime(); setMessage(event.getMessage()); }
Example 6
Source File: RollbarAppender.java From rollbar-java with MIT License | 5 votes |
private Level getLevel(LogEvent event) { org.apache.logging.log4j.Level level = event.getLevel(); Level rollbarLevel = Level.lookupByName(level.name()); if (rollbarLevel != null) { return rollbarLevel; } if (org.apache.logging.log4j.Level.FATAL.equals(level)) { return Level.CRITICAL; } return null; }
Example 7
Source File: TextAreaAppender.java From Flashtool with GNU General Public License v3.0 | 5 votes |
/** * This method is where the appender does the work. * * @param event Log event with log data */ @Override public void append(LogEvent event) { readLock.lock(); String message = new String(getLayout().toByteArray(event)); Level l = event.getLevel(); if (styledText!=null) { StyleRange styleRange = new StyleRange(); if (l==Level.ERROR) { styleRange.length = message.length(); styleRange.fontStyle = SWT.NORMAL; styleRange.foreground = cred; } else if (l==Level.WARN) { styleRange.length = message.length(); styleRange.fontStyle = SWT.NORMAL; styleRange.foreground = cblue; } else { styleRange.length = message.length(); styleRange.fontStyle = SWT.NORMAL; styleRange.foreground = cblack; } Display.getDefault().asyncExec(new Runnable() { public void run() { // Append formatted message to textarea. styleRange.start = styledText.getCharCount(); styledText.append(message); styledText.setStyleRange(styleRange); styledText.setSelection(styledText.getCharCount()); } }); } readLock.unlock(); }
Example 8
Source File: InstrumentedAppender.java From client_java with Apache License 2.0 | 5 votes |
@Override public void append(LogEvent event) { Level level = event.getLevel(); if (TRACE.equals(level)) TRACE_LABEL.inc(); else if (DEBUG.equals(level)) DEBUG_LABEL.inc(); else if (INFO.equals(level)) INFO_LABEL.inc(); else if (WARN.equals(level)) WARN_LABEL.inc(); else if (ERROR.equals(level)) ERROR_LABEL.inc(); else if (FATAL.equals(level)) FATAL_LABEL.inc(); }
Example 9
Source File: LoggerNameLevelRewritePolicy.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override public LogEvent rewrite(final LogEvent event) { if (event.getLoggerName() == null || !event.getLoggerName().startsWith(loggerName)) { return event; } final Level sourceLevel = event.getLevel(); final Level newLevel = map.get(sourceLevel); if (newLevel == null || newLevel == sourceLevel) { return event; } final LogEvent result = new Log4jLogEvent.Builder(event).setLevel(newLevel).build(); return result; }
Example 10
Source File: LevelPatternSelector.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override public PatternFormatter[] getFormatters(final LogEvent event) { final Level level = event.getLevel(); if (level == null) { return defaultFormatters; } for (final String key : formatterMap.keySet()) { if (level.name().equalsIgnoreCase(key)) { return formatterMap.get(key); } } return defaultFormatters; }
Example 11
Source File: LogTestRule.java From ArchUnit with Apache License 2.0 | 4 votes |
RecordedLogEvent(LogEvent event) { this(event.getLevel(), event.getMessage().getFormattedMessage(), event.getThrown()); }
Example 12
Source File: Log4jLogEvent.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public Builder(final LogEvent other) { Objects.requireNonNull(other); if (other instanceof RingBufferLogEvent) { ((RingBufferLogEvent) other).initializeBuilder(this); return; } if (other instanceof MutableLogEvent) { ((MutableLogEvent) other).initializeBuilder(this); return; } this.loggerFqcn = other.getLoggerFqcn(); this.marker = other.getMarker(); this.level = other.getLevel(); this.loggerName = other.getLoggerName(); this.message = other.getMessage(); this.instant.initFrom(other.getInstant()); this.thrown = other.getThrown(); this.contextStack = other.getContextStack(); this.includeLocation = other.isIncludeLocation(); this.endOfBatch = other.isEndOfBatch(); this.nanoTime = other.getNanoTime(); // Avoid unnecessarily initializing thrownProxy, threadName and source if possible if (other instanceof Log4jLogEvent) { final Log4jLogEvent evt = (Log4jLogEvent) other; this.contextData = evt.contextData; this.thrownProxy = evt.thrownProxy; this.source = evt.source; this.threadId = evt.threadId; this.threadName = evt.threadName; this.threadPriority = evt.threadPriority; } else { if (other.getContextData() instanceof StringMap) { this.contextData = (StringMap) other.getContextData(); } else { if (this.contextData.isFrozen()) { this.contextData = ContextDataFactory.createContextData(); } else { this.contextData.clear(); } this.contextData.putAll(other.getContextData()); } this.thrownProxy = other.getThrownProxy(); this.source = other.getSource(); this.threadId = other.getThreadId(); this.threadName = other.getThreadName(); this.threadPriority = other.getThreadPriority(); } }