@MappedSuperclass public abstract class AbstractLogEventWrapperEntity extends Object implements LogEvent
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.
BasicLogEventEntity,
Serialized Form| Modifier | Constructor and Description |
|---|---|
protected |
AbstractLogEventWrapperEntity()
Instantiates this base class.
|
protected |
AbstractLogEventWrapperEntity(LogEvent wrappedEvent)
Instantiates this base class.
|
| Modifier and Type | Method and Description |
|---|---|
protected LogEvent |
getWrappedEvent()
All eventual accessor methods must call this method and delegate the method call to the underlying wrapped event.
|
boolean |
isEndOfBatch()
Indicates whether this event is the last one in a batch.
|
boolean |
isIncludeLocation()
Indicates whether the source of the logging request is required downstream.
|
void |
setContextMap(Map<String,String> contextMap)
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.
|
void |
setEndOfBatch(boolean endOfBatch)
Sets whether this event is the last one in a batch.
|
void |
setIncludeLocation(boolean locationRequired)
Sets whether the source of the logging request is required downstream.
|
void |
setLevel(Level level)
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 |
setMarker(Marker marker)
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 |
setSource(StackTraceElement source)
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 |
setThrown(Throwable throwable)
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetContextMap, getContextStack, getLevel, getLoggerFqcn, getLoggerName, getMarker, getMessage, getSource, getThreadName, getThrown, getThrownProxy, getTimeMillisprotected AbstractLogEventWrapperEntity()
protected AbstractLogEventWrapperEntity(LogEvent wrappedEvent)
wrappedEvent - The underlying event from which information is obtained.protected final LogEvent getWrappedEvent()
Transient so as not to be included in the persisted entity.public void setLevel(Level level)
level - Ignored.public void setLoggerName(String loggerName)
loggerName - Ignored.public void setSource(StackTraceElement source)
source - Ignored.public void setMessage(Message message)
message - Ignored.public void setMarker(Marker marker)
marker - Ignored.public void setThreadName(String threadName)
threadName - Ignored.public void setTimeMillis(long millis)
millis - Ignored.public void setThrown(Throwable throwable)
throwable - Ignored.public void setContextMap(Map<String,String> contextMap)
contextMap - Ignored.public void setContextStack(ThreadContext.ContextStack contextStack)
contextStack - Ignored.public void setLoggerFqcn(String fqcn)
fqcn - Ignored.public final boolean isIncludeLocation()
@Transient so as to not be included in the persisted entity.isIncludeLocation in interface LogEventLogEvent.getSource()public final void setIncludeLocation(boolean locationRequired)
LogEventStackTrace snapshot or not before handing off this event to
another thread.setIncludeLocation in interface LogEventlocationRequired - true if the source of the logging request is required downstream, false
otherwise.LogEvent.getSource()public final boolean isEndOfBatch()
@Transient so as to not be
included in the persisted entity.isEndOfBatch in interface LogEventpublic final void setEndOfBatch(boolean endOfBatch)
LogEventimmediateFlush=true configuration.setEndOfBatch in interface LogEventendOfBatch - true if this event is the last one in a batch, false otherwise.Copyright © 1999-2021 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.