Class BasicLogEventEntity
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.db.jpa.AbstractLogEventWrapperEntity
-
- org.apache.logging.log4j.core.appender.db.jpa.BasicLogEventEntity
-
- All Implemented Interfaces:
java.io.Serializable
,LogEvent
@MappedSuperclass public abstract class BasicLogEventEntity extends AbstractLogEventWrapperEntity
Users of the JPA appender may want to extend this class instead ofAbstractLogEventWrapperEntity
. This class implements all of the required mutator methods but does not implement a mutable entity ID property. In order to create an entity based on this class, you need only create two constructors matching this class's constructors, annotate the class@Entity
and@Table
, and implement the fully mutable entity ID property annotated with@Id
and@GeneratedValue
to tell the JPA provider how to calculate an ID for new events.
The attributes in this entity use the default column names (which, according to the JPA spec, are the property names minus the "get" and "set" from the accessors/mutators). If you want to use different column names for one or more columns, override the necessary accessor methods defined in this class with the same annotations plus the@Column
annotation to specify the column name.
ThegetContextMap()
andgetContextStack()
attributes in this entity use theContextMapAttributeConverter
andContextStackAttributeConverter
, respectively. These convert the properties to simple strings that cannot be converted back to the properties. If you wish to instead convert these to a reversible JSON string, override these attributes with the same annotations but use theContextMapJsonAttributeConverter
andContextStackJsonAttributeConverter
instead.
All other attributes in this entity use reversible converters that can be used for both persistence and retrieval. If there are any attributes you do not want persistent, you should override their accessor methods and annotate with@Transient
.- See Also:
AbstractLogEventWrapperEntity
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BasicLogEventEntity()
Instantiates this base class.BasicLogEventEntity(LogEvent wrappedEvent)
Instantiates this base class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.String>
getContextMap()
Gets the context map.ThreadContext.ContextStack
getContextStack()
Gets the context stack.Level
getLevel()
Gets the level.java.lang.String
getLoggerFqcn()
Gets the fully qualified class name of the caller of the logger API.java.lang.String
getLoggerName()
Gets the logger name.Marker
getMarker()
Gets the marker.Message
getMessage()
Gets the message.long
getNanoTime()
Returns the value of the running Java Virtual Machine's high-resolution time source when this event was created, or a dummy value if it is known that this value will not be used downstream.java.lang.StackTraceElement
getSource()
Gets the source location information.long
getThreadId()
Gets the thread ID.java.lang.String
getThreadName()
Gets the thread name.int
getThreadPriority()
Gets the thread name.java.lang.Throwable
getThrown()
Gets the exception logged.ThrowableProxy
getThrownProxy()
Gets the exception logged.long
getTimeMillis()
Gets the number of milliseconds since JVM launch.-
Methods inherited from class org.apache.logging.log4j.core.appender.db.jpa.AbstractLogEventWrapperEntity
getContextData, getWrappedEvent, isEndOfBatch, isIncludeLocation, setContextData, setContextMap, setContextStack, setEndOfBatch, setIncludeLocation, setLevel, setLoggerFqcn, setLoggerName, setMarker, setMessage, setNanoTime, setSource, setThreadId, setThreadName, setThreadPriority, setThrown, setTimeMillis, toImmutable
-
-
-
-
Constructor Detail
-
BasicLogEventEntity
public BasicLogEventEntity()
Instantiates this base class. All concrete implementations must have a constructor matching this constructor's signature. The no-argument constructor is required for a standards-compliant JPA provider to accept this as an entity.
-
BasicLogEventEntity
public BasicLogEventEntity(LogEvent wrappedEvent)
Instantiates this base class. All concrete implementations must have a constructor matching this constructor's signature. This constructor is used for wrapping this entity around a logged event.- Parameters:
wrappedEvent
- The underlying event from which information is obtained.
-
-
Method Detail
-
getLevel
public Level getLevel()
Gets the level. Annotated with@Basic
and@Enumerated(EnumType.STRING)
.- Returns:
- the level.
-
getLoggerName
public java.lang.String getLoggerName()
Gets the logger name. Annotated with@Basic
.- Returns:
- the logger name.
-
getSource
public java.lang.StackTraceElement getSource()
Gets the source location information. Annotated with@Convert(converter = StackTraceElementAttributeConverter.class)
.- Returns:
- the source location information.
- See Also:
StackTraceElementAttributeConverter
-
getMessage
public Message getMessage()
Gets the message. Annotated with@Convert(converter = MessageAttributeConverter.class)
.- Returns:
- the message.
- See Also:
MessageAttributeConverter
-
getMarker
public Marker getMarker()
Gets the marker. Annotated with@Convert(converter = MarkerAttributeConverter.class)
.- Returns:
- the marker.
- See Also:
MarkerAttributeConverter
-
getThreadId
public long getThreadId()
Gets the thread ID. Annotated with@Basic
.- Returns:
- the thread ID.
-
getThreadPriority
public int getThreadPriority()
Gets the thread name. Annotated with@Basic
.- Returns:
- the thread name.
-
getThreadName
public java.lang.String getThreadName()
Gets the thread name. Annotated with@Basic
.- Returns:
- the thread name.
-
getTimeMillis
public long getTimeMillis()
Gets the number of milliseconds since JVM launch. Annotated with@Basic
.- Returns:
- the number of milliseconds since JVM launch.
- See Also:
System.currentTimeMillis()
-
getNanoTime
public long getNanoTime()
Returns the value of the running Java Virtual Machine's high-resolution time source when this event was created, or a dummy value if it is known that this value will not be used downstream.- Returns:
- the JVM nano time
-
getThrown
public java.lang.Throwable getThrown()
Gets the exception logged. Annotated with@Convert(converter = ThrowableAttributeConverter.class)
.- Returns:
- the exception logged.
- See Also:
ThrowableAttributeConverter
-
getThrownProxy
public ThrowableProxy getThrownProxy()
Gets the exception logged. Annotated with@Convert(converter = ThrowableAttributeConverter.class)
.- Returns:
- the exception logged.
- See Also:
ThrowableAttributeConverter
-
getContextMap
public java.util.Map<java.lang.String,java.lang.String> getContextMap()
Gets the context map. Annotated with@Convert(converter = ContextMapAttributeConverter.class)
.- Returns:
- the context map.
- See Also:
ContextMapAttributeConverter
,ContextMapJsonAttributeConverter
-
getContextStack
public ThreadContext.ContextStack getContextStack()
Gets the context stack. Annotated with@Convert(converter = ContextStackAttributeConverter.class)
.- Returns:
- the context stack.
- See Also:
ContextStackAttributeConverter
,ContextStackJsonAttributeConverter
-
getLoggerFqcn
public java.lang.String getLoggerFqcn()
Gets the fully qualified class name of the caller of the logger API. Annotated with@Basic
.- Returns:
- the fully qualified class name of the caller of the logger API.
-
-