public class HybrisLogger
extends Logger
The reason for for using an own logger with listener concept, is the lack of context dependent filtering of log
messages before calling the log method. Our use case is the specialized logging within a job instance, besides the
normal logging. Here, there are two outputs (to database and file) additional to the normal output each with
different and at runtime configurable log level. Because the support of thread-hierarchical logging is not supported
you have to store the job instance local to the thread to determine while logging which appenders and log level is
needed (When a job is set to the current thread we have to log additionally to the two outputs with special log
levels). The easiest way is to set the global log level to debug, realize the additional outputs with
org.apache.log4j.Appenders and for deciding whether log messages have to use the normal and/or other appender
a Filter for each appender can be used. Problem is, you call the log method (isEnableFor is always true because of
global debug), then the filter of each appender filters the not used logs dependent on level and then the log is
putted out to the appender. So, each time the log method is used, even when a log is filtered completely. This is a
performance bottleneck. So, the [y]hybris logger overwrites the isEnabledFor(..) methods to check for logging needs
before calling the log methods.
See PLA-148 for further details.
The reason for for using an own logger with filter concept, is the lack of extending the real log message in some
specific situations after a log method is called. The only chance to do this is the usage of the
org.apache.log4j.MDC or org.apache.log4j.NDC class, but the extending of the log has to be configured
at the appender. If the message only has to be extended in some situations (here if the ImpEx extension logs
something), it is not acceptable to modify the pattern layout. (The extending of the message in case for ImpEx has to
be done always and there is no need to remove it from the pattern layout. So it is a better to not mention it at the
layout configuration, it only confuses the user).
See PLA-5328 for further details.
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
slf4jLogger |
| Modifier | Constructor and Description |
|---|---|
protected |
HybrisLogger(java.lang.String name)
Instantiates a new logger with given name.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
addFilter(HybrisLogFilter newFilter)
Adds a log filter to the static list of filters.
|
static void |
addFilterFirst(HybrisLogFilter newFilter)
Adds a log filter to the static list of filters.
|
static void |
addListener(HybrisLogListener newListener)
Adds a log listener to the static list of listeners.
|
void |
debug(java.lang.Object message) |
void |
debug(java.lang.Object message,
java.lang.Throwable throwable) |
static void |
disableListeners() |
static void |
enableListeners() |
void |
error(java.lang.Object message) |
void |
error(java.lang.Object message,
java.lang.Throwable throwable) |
protected boolean |
existsListenerEnabledFor(Priority level)
Does a listener exists in the static list of listener, which is enabled for given log level?
|
static HybrisLoggingEvent |
extendByFilters(HybrisLoggingEvent event)
Calls all filter sequential in list order.
|
void |
fatal(java.lang.Object message) |
void |
fatal(java.lang.Object message,
java.lang.Throwable throwable) |
static java.util.List<HybrisLogListener> |
getAllAListeners() |
static java.util.List<HybrisLogFilter> |
getFilters() |
void |
info(java.lang.Object message) |
void |
info(java.lang.Object message,
java.lang.Throwable throwable) |
boolean |
isDebugEnabled() |
boolean |
isEnabledFor(Priority level) |
boolean |
isInfoEnabled() |
protected static boolean |
isThreadCurrentlyLoggingToListeners() |
void |
log(Priority priority,
java.lang.Object message) |
void |
log(Priority priority,
java.lang.Object message,
java.lang.Throwable t) |
void |
log(java.lang.String callerFQCN,
Priority level,
java.lang.Object message,
java.lang.Throwable t) |
static void |
logToListeners(HybrisLoggingEvent event)
Calls all listeners with given log event which are enabled for level of log.
|
protected static void |
markThreadCurrentlyLoggingToListeners() |
static void |
removeAllListeners()
Removes all listeners from the list
|
static boolean |
removeFilter(HybrisLogFilter toRemove)
Removes a filter from the list of filters and therefore will not be called anymore.
|
static boolean |
removeListener(HybrisLogListener toRemove)
Removes the first occurrence in the static listener list of the specified listener If the list does not contain
the element, it is unchanged.
|
void |
setLevel(Level level) |
protected static void |
unsetThreadCurrentlyLoggingToListeners() |
void |
warn(java.lang.Object message) |
void |
warn(java.lang.Object message,
java.lang.Throwable throwable) |
protected HybrisLogger(java.lang.String name)
getLogger(..).name - name of the loggerpublic static void disableListeners()
public static void enableListeners()
public static void addFilter(HybrisLogFilter newFilter)
newFilter - filter which will be called before a log is loggedpublic static void addFilterFirst(HybrisLogFilter newFilter)
newFilter - filter which will be called before a log is loggedpublic static boolean removeFilter(HybrisLogFilter toRemove)
toRemove - filter to removepublic static HybrisLoggingEvent extendByFilters(HybrisLoggingEvent event)
event - log event which will be passed to each filter and can be modifiedpublic static void addListener(HybrisLogListener newListener)
newListener - listener which will be called from now when a log is given.public static boolean removeListener(HybrisLogListener toRemove)
toRemove - listener to be removed from listener list, if present.public static void removeAllListeners()
public static java.util.List<HybrisLogListener> getAllAListeners()
protected boolean existsListenerEnabledFor(Priority level)
level - the level for which the listeners will be checkedpublic static void logToListeners(HybrisLoggingEvent event)
event - the log event the listeners will be calledprotected static boolean isThreadCurrentlyLoggingToListeners()
protected static void markThreadCurrentlyLoggingToListeners()
protected static void unsetThreadCurrentlyLoggingToListeners()
public void debug(java.lang.Object message)
public void debug(java.lang.Object message,
java.lang.Throwable throwable)
public void error(java.lang.Object message)
public void error(java.lang.Object message,
java.lang.Throwable throwable)
public void fatal(java.lang.Object message)
public void fatal(java.lang.Object message,
java.lang.Throwable throwable)
public void info(java.lang.Object message)
public void warn(java.lang.Object message,
java.lang.Throwable throwable)
public void warn(java.lang.Object message)
public void info(java.lang.Object message,
java.lang.Throwable throwable)
public void log(java.lang.String callerFQCN,
Priority level,
java.lang.Object message,
java.lang.Throwable t)
public void log(Priority priority,
java.lang.Object message)
public void log(Priority priority,
java.lang.Object message,
java.lang.Throwable t)
public boolean isDebugEnabled()
public boolean isEnabledFor(Priority level)
public void setLevel(Level level)
public boolean isInfoEnabled()
public static java.util.List<HybrisLogFilter> getFilters()
Copyright © 2018 SAP SE. All Rights Reserved.