Class AbstractLogEventWrapperEntity
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.db.jpa.AbstractLogEventWrapperEntity
-
- All Implemented Interfaces:
java.io.Serializable,LogEvent
- Direct Known Subclasses:
BasicLogEventEntity
@MappedSuperclass public abstract class AbstractLogEventWrapperEntity extends java.lang.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 callgetWrappedEvent()and delegate the call to the underlying event. Users may want to instead extendBasicLogEventEntity, 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
eventand passes it to the parent class withsuper(event). Furthermore, the concrete class must be annotated@Entityand@Tableand must implement a fully mutable ID property annotated with@Idand@GeneratedValueto tell the JPA provider how to calculate an ID for new events.Many of the return types of
LogEventmethods (e.g.,StackTraceElement,Message,Marker,Throwable,ThreadContext.ContextStack, andMap<String, String>) will not be recognized by the JPA provider. In conjunction with@Convert, you can use the converters in theorg.apache.logging.log4j.core.appender.db.jpa.converterpackage 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
LogEventare 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:
BasicLogEventEntity, Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractLogEventWrapperEntity()Instantiates this base class.protectedAbstractLogEventWrapperEntity(LogEvent wrappedEvent)Instantiates this base class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ReadOnlyStringMapgetContextData()Gets the context map.protected LogEventgetWrappedEvent()All eventual accessor methods must call this method and delegate the method call to the underlying wrapped event.booleanisEndOfBatch()Indicates whether this event is the last one in a batch.booleanisIncludeLocation()Indicates whether the source of the logging request is required downstream.voidsetContextData(ReadOnlyStringMap contextData)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetContextMap(java.util.Map<java.lang.String,java.lang.String> map)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetContextStack(ThreadContext.ContextStack contextStack)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetEndOfBatch(boolean endOfBatch)Sets whether this event is the last one in a batch.voidsetIncludeLocation(boolean locationRequired)Sets whether the source of the logging request is required downstream.voidsetLevel(Level level)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetLoggerFqcn(java.lang.String fqcn)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetLoggerName(java.lang.String loggerName)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetMarker(Marker marker)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetMessage(Message message)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetNanoTime(long nanoTime)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetSource(java.lang.StackTraceElement source)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetThreadId(long threadId)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetThreadName(java.lang.String threadName)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetThreadPriority(int threadPriority)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetThrown(java.lang.Throwable throwable)A no-op mutator to satisfy JPA requirements, as this entity is write-only.voidsetTimeMillis(long millis)A no-op mutator to satisfy JPA requirements, as this entity is write-only.LogEventtoImmutable()Returns an immutable version of this log event, which MAY BE a copy of this event.-
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, getLevel, getLoggerFqcn, getLoggerName, getMarker, getMessage, getNanoTime, getSource, getThreadId, getThreadName, getThreadPriority, getThrown, getThrownProxy, getTimeMillis
-
-
-
-
Constructor Detail
-
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
protected AbstractLogEventWrapperEntity(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
-
toImmutable
public LogEvent toImmutable()
Description copied from interface:LogEventReturns an immutable version of this log event, which MAY BE a copy of this event.- Specified by:
toImmutablein interfaceLogEvent- Returns:
- an immutable version of this log event
-
getWrappedEvent
protected final LogEvent getWrappedEvent()
All eventual accessor methods must call this method and delegate the method call to the underlying wrapped event. AnnotatedTransientso as not to be included in the persisted entity.- Returns:
- The underlying event from which information is obtained.
-
setLevel
public void setLevel(Level level)
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
level- Ignored.
-
setLoggerName
public void setLoggerName(java.lang.String loggerName)
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
loggerName- Ignored.
-
setSource
public void setSource(java.lang.StackTraceElement source)
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
source- Ignored.
-
setMessage
public void setMessage(Message message)
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
message- Ignored.
-
setMarker
public void setMarker(Marker marker)
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
public void setThreadName(java.lang.String threadName)
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.
-
setThrown
public void setThrown(java.lang.Throwable throwable)
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
throwable- Ignored.
-
setContextData
public void setContextData(ReadOnlyStringMap contextData)
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
contextData- Ignored.
-
setContextMap
public void setContextMap(java.util.Map<java.lang.String,java.lang.String> map)
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
map- Ignored.
-
setContextStack
public void setContextStack(ThreadContext.ContextStack contextStack)
A no-op mutator to satisfy JPA requirements, as this entity is write-only.- Parameters:
contextStack- Ignored.
-
setLoggerFqcn
public void setLoggerFqcn(java.lang.String fqcn)
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@Transientso as to not be included in the persisted entity.- Specified by:
isIncludeLocationin interfaceLogEvent- Returns:
- whether the source of the logging request is required downstream.
- See Also:
LogEvent.getSource()
-
setIncludeLocation
public final void setIncludeLocation(boolean locationRequired)
Description copied from interface:LogEventSets whether the source of the logging request is required downstream. Asynchronous Loggers and Appenders use this flag to determine whether to take aStackTracesnapshot or not before handing off this event to another thread.- Specified by:
setIncludeLocationin interfaceLogEvent- Parameters:
locationRequired-trueif the source of the logging request is required downstream,falseotherwise.- See Also:
LogEvent.getSource()
-
isEndOfBatch
public final boolean isEndOfBatch()
Indicates whether this event is the last one in a batch. Annotated@Transientso as to not be included in the persisted entity.- Specified by:
isEndOfBatchin interfaceLogEvent- Returns:
- whether this event is the last one in a batch.
-
setEndOfBatch
public final void setEndOfBatch(boolean endOfBatch)
Description copied from interface:LogEventSets 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 theimmediateFlush=trueconfiguration.- Specified by:
setEndOfBatchin interfaceLogEvent- Parameters:
endOfBatch-trueif this event is the last one in a batch,falseotherwise.
-
getContextData
public ReadOnlyStringMap getContextData()
Gets the context map. Transient, since the String version of the data is obtained via ReadOnlyStringMap.- Specified by:
getContextDatain interfaceLogEvent- Returns:
- the context data.
- See Also:
ContextDataAttributeConverter,ContextDataAttributeConverter
-
-