Class AbstractLogEventWrapperEntity
- All Implemented Interfaces:
Serializable
,LogEvent
- Direct Known Subclasses:
BasicLogEventEntity
Users of the JPA appender MUST extend this class, using JPA annotations on the concrete class and all of its
accessor methods (as needed) to map them to the proper table and columns. Accessors you do not want persisted should
be annotated with @Transient
. All accessors should call getWrappedEvent()
and delegate the
call to the underlying event. Users may want to instead extend BasicLogEventEntity
, which takes care of all
of this for you.
The concrete class must have two constructors: a public no-arg constructor to convince the JPA provider that it's a
valid entity, and a public constructor that takes a single event
and passes it to the parent class
with super(event)
. Furthermore, the concrete class must be annotated
@Entity
and @Table
and must implement a fully
mutable ID property annotated with @Id
and
@GeneratedValue
to tell the JPA provider how to calculate an ID for new
events.
Many of the return types of LogEvent
methods (e.g., StackTraceElement
, Message
,
Marker
, Throwable
,
ThreadContext.ContextStack
, and
Map<String, String>
) will not be recognized by the JPA provider. In conjunction with
@Convert
, you can use the converters in the
org.apache.logging.log4j.core.appender.db.jpa.converter
package to convert these types to database columns.
If you want to retrieve log events from the database, you can create a true POJO entity and also use these
converters for extracting persisted values.
The mutator methods in this class not specified in LogEvent
are no-op methods, implemented to satisfy the JPA
requirement that accessor methods have matching mutator methods. If you create additional accessor methods, you must
likewise create matching no-op mutator methods.
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
Instantiates this base class.protected
AbstractLogEventWrapperEntity
(LogEvent wrappedEvent) Instantiates this base class. -
Method Summary
Modifier and TypeMethodDescriptionGets the context map.protected final LogEvent
All eventual accessor methods must call this method and delegate the method call to the underlying wrapped event.final boolean
Indicates whether this event is the last one in a batch.final boolean
Indicates whether the source of the logging request is required downstream.void
setContextData
(ReadOnlyStringMap contextData) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setContextMap
(Map<String, String> map) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setContextStack
(ThreadContext.ContextStack contextStack) A no-op mutator to satisfy JPA requirements, as this entity is write-only.final void
setEndOfBatch
(boolean endOfBatch) final void
setIncludeLocation
(boolean locationRequired) void
setInstant
(Instant instant) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setLoggerFqcn
(String fqcn) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setLoggerName
(String loggerName) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setMessage
(Message message) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setNanoOfMillisecond
(int nanoOfMillisecond) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setNanoTime
(long nanoTime) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setSource
(StackTraceElement source) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setThreadId
(long threadId) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setThreadName
(String threadName) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setThreadPriority
(int threadPriority) A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
A no-op mutator to satisfy JPA requirements, as this entity is write-only.void
setTimeMillis
(long millis) A no-op mutator to satisfy JPA requirements, as this entity is write-only.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.logging.log4j.core.LogEvent
getContextMap, getContextStack, getInstant, getLevel, getLoggerFqcn, getLoggerName, getMarker, getMessage, getNanoTime, getSource, getThreadId, getThreadName, getThreadPriority, getThrown, getThrownProxy, getTimeMillis
-
Constructor Details
-
AbstractLogEventWrapperEntity
protected AbstractLogEventWrapperEntity()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. -
AbstractLogEventWrapperEntity
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 Details
-
toImmutable
- Specified by:
toImmutable
in interfaceLogEvent
-
getWrappedEvent
All eventual accessor methods must call this method and delegate the method call to the underlying wrapped event. AnnotatedTransient
so as not to be included in the persisted entity.- Returns:
- The underlying event from which information is obtained.
-
setLevel
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
level
- Ignored.
-
setLoggerName
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
loggerName
- Ignored.
-
setSource
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
source
- Ignored.
-
setMessage
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
message
- Ignored.
-
setMarker
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
marker
- Ignored.
-
setThreadId
public void setThreadId(long threadId) A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
threadId
- Ignored.
-
setThreadName
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
threadName
- Ignored.
-
setThreadPriority
public void setThreadPriority(int threadPriority) A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
threadPriority
- Ignored.
-
setNanoTime
public void setNanoTime(long nanoTime) A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
nanoTime
- Ignored.
-
setTimeMillis
public void setTimeMillis(long millis) A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
millis
- Ignored.
-
setInstant
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
instant
- Ignored.
-
setNanoOfMillisecond
public void setNanoOfMillisecond(int nanoOfMillisecond) A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
nanoOfMillisecond
- Ignored.
-
setThrown
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
throwable
- Ignored.
-
setContextData
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
contextData
- Ignored.
-
setContextMap
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
map
- Ignored.
-
setContextStack
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
contextStack
- Ignored.
-
setLoggerFqcn
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
fqcn
- Ignored.
-
isIncludeLocation
public final boolean isIncludeLocation()Indicates whether the source of the logging request is required downstream. Annotated@Transient
so as to not be included in the persisted entity.- Specified by:
isIncludeLocation
in interfaceLogEvent
- Returns:
- whether the source of the logging request is required downstream.
-
setIncludeLocation
public final void setIncludeLocation(boolean locationRequired) - Specified by:
setIncludeLocation
in interfaceLogEvent
-
isEndOfBatch
public final boolean isEndOfBatch()Indicates whether this event is the last one in a batch. Annotated@Transient
so as to not be included in the persisted entity.- Specified by:
isEndOfBatch
in interfaceLogEvent
- Returns:
- whether this event is the last one in a batch.
-
setEndOfBatch
public final void setEndOfBatch(boolean endOfBatch) - Specified by:
setEndOfBatch
in interfaceLogEvent
-
getContextData
Gets the context map. Transient, since the String version of the data is obtained via ReadOnlyStringMap.- Specified by:
getContextData
in interfaceLogEvent
- Returns:
- the context data.
- See Also:
-