org.apache.logging.log4j.core.impl
Class Log4jLogEvent

java.lang.Object
  extended by org.apache.logging.log4j.core.impl.Log4jLogEvent
All Implemented Interfaces:
Serializable, LogEvent

public class Log4jLogEvent
extends Object
implements LogEvent

Implementation of a LogEvent.

See Also:
Serialized Form

Constructor Summary
Log4jLogEvent()
           
Log4jLogEvent(long timestamp)
           
Log4jLogEvent(String loggerName, org.apache.logging.log4j.Marker marker, String loggerFQCN, org.apache.logging.log4j.Level level, org.apache.logging.log4j.message.Message message, List<Property> properties, Throwable t)
          Constructor.
Log4jLogEvent(String loggerName, org.apache.logging.log4j.Marker marker, String loggerFQCN, org.apache.logging.log4j.Level level, org.apache.logging.log4j.message.Message message, Throwable t)
          Constructor.
Log4jLogEvent(String loggerName, org.apache.logging.log4j.Marker marker, String loggerFQCN, org.apache.logging.log4j.Level level, org.apache.logging.log4j.message.Message message, Throwable t, Map<String,String> mdc, org.apache.logging.log4j.ThreadContext.ContextStack ndc, String threadName, StackTraceElement location, long timestamp)
          Constructor.
 
Method Summary
static StackTraceElement calcLocation(String fqcnOfLogger)
           
static boolean canDeserialize(Serializable event)
           
static Log4jLogEvent createEvent(String loggerName, org.apache.logging.log4j.Marker marker, String loggerFQCN, org.apache.logging.log4j.Level level, org.apache.logging.log4j.message.Message message, Throwable thrown, ThrowableProxy thrownProxy, Map<String,String> mdc, org.apache.logging.log4j.ThreadContext.ContextStack ndc, String threadName, StackTraceElement location, long timestamp)
          Create a new LogEvent.
static Log4jLogEvent deserialize(Serializable event)
           
 boolean equals(Object o)
           
 Map<String,String> getContextMap()
          Returns the immutable copy of the ThreadContext Map.
 org.apache.logging.log4j.ThreadContext.ContextStack getContextStack()
          Returns an immutable copy of the ThreadContext stack.
 org.apache.logging.log4j.Level getLevel()
          Returns the logging Level.
 String getLoggerFqcn()
          The fully qualified class name of the class that was called by the caller.
 String getLoggerName()
          Returns the name of the Logger used to generate the event.
 org.apache.logging.log4j.Marker getMarker()
          Returns the Marker associated with the event, or null.
 org.apache.logging.log4j.message.Message getMessage()
          Returns the Message associated with the event.
 StackTraceElement getSource()
          Returns the StackTraceElement for the caller.
 String getThreadName()
          Returns the name of the Thread on which the event was generated.
 Throwable getThrown()
          Returns the Throwable associated with the event, or null.
 ThrowableProxy getThrownProxy()
          Returns the ThrowableProxy associated with the event, or null.
 long getTimeMillis()
          Returns the time in milliseconds from the epoch when the event occurred.
 int hashCode()
           
 boolean isEndOfBatch()
          Returns true if this event is the last one in a batch, false otherwise.
 boolean isIncludeLocation()
          Returns whether the source of the logging request is required downstream.
static Serializable serialize(Log4jLogEvent event, boolean includeLocation)
           
 void setEndOfBatch(boolean endOfBatch)
          Sets whether this event is the last one in a batch.
 void setIncludeLocation(boolean includeLocation)
          Sets whether the source of the logging request is required downstream.
 String toString()
           
protected  Object writeReplace()
          Creates a LogEventProxy that can be serialized.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Log4jLogEvent

public Log4jLogEvent()

Log4jLogEvent

public Log4jLogEvent(long timestamp)

Log4jLogEvent

public Log4jLogEvent(String loggerName,
                     org.apache.logging.log4j.Marker marker,
                     String loggerFQCN,
                     org.apache.logging.log4j.Level level,
                     org.apache.logging.log4j.message.Message message,
                     Throwable t)
Constructor.

Parameters:
loggerName - The name of the Logger.
marker - The Marker or null.
loggerFQCN - The fully qualified class name of the caller.
level - The logging Level.
message - The Message.
t - A Throwable or null.

Log4jLogEvent

public Log4jLogEvent(String loggerName,
                     org.apache.logging.log4j.Marker marker,
                     String loggerFQCN,
                     org.apache.logging.log4j.Level level,
                     org.apache.logging.log4j.message.Message message,
                     List<Property> properties,
                     Throwable t)
Constructor.

Parameters:
loggerName - The name of the Logger.
marker - The Marker or null.
loggerFQCN - The fully qualified class name of the caller.
level - The logging Level.
message - The Message.
properties - properties to add to the event.
t - A Throwable or null.

Log4jLogEvent

public Log4jLogEvent(String loggerName,
                     org.apache.logging.log4j.Marker marker,
                     String loggerFQCN,
                     org.apache.logging.log4j.Level level,
                     org.apache.logging.log4j.message.Message message,
                     Throwable t,
                     Map<String,String> mdc,
                     org.apache.logging.log4j.ThreadContext.ContextStack ndc,
                     String threadName,
                     StackTraceElement location,
                     long timestamp)
Constructor.

Parameters:
loggerName - The name of the Logger.
marker - The Marker or null.
loggerFQCN - The fully qualified class name of the caller.
level - The logging Level.
message - The Message.
t - A Throwable or null.
mdc - The mapped diagnostic context.
ndc - the nested diagnostic context.
threadName - The name of the thread.
location - The locations of the caller.
timestamp - The timestamp of the event.
Method Detail

createEvent

public static Log4jLogEvent createEvent(String loggerName,
                                        org.apache.logging.log4j.Marker marker,
                                        String loggerFQCN,
                                        org.apache.logging.log4j.Level level,
                                        org.apache.logging.log4j.message.Message message,
                                        Throwable thrown,
                                        ThrowableProxy thrownProxy,
                                        Map<String,String> mdc,
                                        org.apache.logging.log4j.ThreadContext.ContextStack ndc,
                                        String threadName,
                                        StackTraceElement location,
                                        long timestamp)
Create a new LogEvent.

Parameters:
loggerName - The name of the Logger.
marker - The Marker or null.
loggerFQCN - The fully qualified class name of the caller.
level - The logging Level.
message - The Message.
thrown - A Throwable or null.
thrownProxy - A ThrowableProxy or null.
mdc - The mapped diagnostic context.
ndc - the nested diagnostic context.
threadName - The name of the thread.
location - The locations of the caller.
timestamp - The timestamp of the event.

getLevel

public org.apache.logging.log4j.Level getLevel()
Returns the logging Level.

Specified by:
getLevel in interface LogEvent
Returns:
the Level associated with this event.

getLoggerName

public String getLoggerName()
Returns the name of the Logger used to generate the event.

Specified by:
getLoggerName in interface LogEvent
Returns:
The Logger name.

getMessage

public org.apache.logging.log4j.message.Message getMessage()
Returns the Message associated with the event.

Specified by:
getMessage in interface LogEvent
Returns:
The Message.

getThreadName

public String getThreadName()
Returns the name of the Thread on which the event was generated.

Specified by:
getThreadName in interface LogEvent
Returns:
The name of the Thread.

getTimeMillis

public long getTimeMillis()
Returns the time in milliseconds from the epoch when the event occurred.

Specified by:
getTimeMillis in interface LogEvent
Returns:
The time the event occurred.
See Also:
System.currentTimeMillis()

getThrown

public Throwable getThrown()
Returns the Throwable associated with the event, or null.

Specified by:
getThrown in interface LogEvent
Returns:
The Throwable associated with the event.

getThrownProxy

public ThrowableProxy getThrownProxy()
Returns the ThrowableProxy associated with the event, or null.

Specified by:
getThrownProxy in interface LogEvent
Returns:
The ThrowableProxy associated with the event.

getMarker

public org.apache.logging.log4j.Marker getMarker()
Returns the Marker associated with the event, or null.

Specified by:
getMarker in interface LogEvent
Returns:
the Marker associated with the event.

getLoggerFqcn

public String getLoggerFqcn()
The fully qualified class name of the class that was called by the caller.

Specified by:
getLoggerFqcn in interface LogEvent
Returns:
the fully qualified class name of the class that is performing logging.

getContextMap

public Map<String,String> getContextMap()
Returns the immutable copy of the ThreadContext Map.

Specified by:
getContextMap in interface LogEvent
Returns:
The context Map.

getContextStack

public org.apache.logging.log4j.ThreadContext.ContextStack getContextStack()
Returns an immutable copy of the ThreadContext stack.

Specified by:
getContextStack in interface LogEvent
Returns:
The context Stack.

getSource

public StackTraceElement getSource()
Returns the StackTraceElement for the caller. This will be the entry that occurs right before the first occurrence of FQCN as a class name.

Specified by:
getSource in interface LogEvent
Returns:
the StackTraceElement for the caller.

calcLocation

public static StackTraceElement calcLocation(String fqcnOfLogger)

isIncludeLocation

public boolean isIncludeLocation()
Description copied from interface: LogEvent
Returns whether the source of the logging request is required downstream. Asynchronous Loggers and Appenders use this flag to determine whether to take a StackTrace snapshot or not before handing off this event to another thread.

Specified by:
isIncludeLocation in interface LogEvent
Returns:
true if the source of the logging request is required downstream, false otherwise.
See Also:
LogEvent.getSource()

setIncludeLocation

public void setIncludeLocation(boolean includeLocation)
Description copied from interface: LogEvent
Sets whether the source of the logging request is required downstream. Asynchronous Loggers and Appenders use this flag to determine whether to take a StackTrace snapshot or not before handing off this event to another thread.

Specified by:
setIncludeLocation in interface LogEvent
Parameters:
includeLocation - true if the source of the logging request is required downstream, false otherwise.
See Also:
LogEvent.getSource()

isEndOfBatch

public boolean isEndOfBatch()
Description copied from interface: LogEvent
Returns true if this event is the last one in a batch, false otherwise. Used by asynchronous Loggers and Appenders to signal to buffered downstream components when to flush to disk, as a more efficient alternative to the immediateFlush=true configuration.

Specified by:
isEndOfBatch in interface LogEvent
Returns:
whether this event is the last one in a batch.

setEndOfBatch

public void setEndOfBatch(boolean endOfBatch)
Description copied from interface: LogEvent
Sets whether this event is the last one in a batch. Used by asynchronous Loggers and Appenders to signal to buffered downstream components when to flush to disk, as a more efficient alternative to the immediateFlush=true configuration.

Specified by:
setEndOfBatch in interface LogEvent
Parameters:
endOfBatch - true if this event is the last one in a batch, false otherwise.

writeReplace

protected Object writeReplace()
Creates a LogEventProxy that can be serialized.

Returns:
a LogEventProxy.

serialize

public static Serializable serialize(Log4jLogEvent event,
                                     boolean includeLocation)

canDeserialize

public static boolean canDeserialize(Serializable event)

deserialize

public static Log4jLogEvent deserialize(Serializable event)

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 1999-2014 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.