Java Code Examples for org.apache.logging.log4j.core.LogEvent#getLoggerFqcn()

The following examples show how to use org.apache.logging.log4j.core.LogEvent#getLoggerFqcn() . 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: Log4jLogEvent.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
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 2
Source File: MutableLogEvent.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: Log4jLogEvent.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
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();
    }
}