|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.logging.Logger
public class Logger
Logger somewhat leans on the functionality of the java.util.logging functionality of J2SE 1.4, but it's not quite the same (and was implemented before J2SE 1.4).
In addition to the J2SE functionality, it provides the full stack trace for the log. Whether or not the logging here is written synchronously or asynchronously, is left to the implementation for each LogWriter that is used with the Logger.
All logging methods may throw LogException - propagated from the LogWriter objects contained in the logger to the calling thread. The writing to the different LogWriters is always performed sequentially in the order the LogWriters were added to the Logger.
It is recommended to always use a log method with the origin parameter and pass the 'this' argument from the calling function; this will provide useful additional information for the log.
LogWriter,
LoggerCache,
LogEntry,
LogException| Field Summary |
|---|
| Fields inherited from interface com.antelmann.util.Filter |
|---|
EXCLUDE_ALL_FILTER, INCLUDE_ALL_FILTER |
| Fields inherited from interface com.antelmann.util.Enabled |
|---|
FILTER |
| Constructor Summary | |
|---|---|
Logger()
creates an empty Logger that does not write to any log yet |
|
Logger(Logger logger)
uses the configuration from the given logger (including writers and filter) |
|
Logger(LogWriter... writer)
|
|
| Method Summary | ||
|---|---|---|
boolean |
accept(LogEntry entry)
returns true only if the given entry will be logged by this logger and thus propagated to its handlers |
|
boolean |
addWriter(LogWriter writer)
adds the given handler to the list of handlers this Logger writes to |
|
void |
addWritersFromLogger(Logger logger)
adds all LogWriter handler from the given logger |
|
void |
clearLast()
sets the last logged entry to null |
|
void |
closeAllWriters()
convenience method: attempts to close all embedded writers - if applicable |
|
boolean |
containsWriter(LogWriter writer)
|
|
LogExceptionHandler |
getExceptionHandler()
if the LogExceptionHandler is null (which it is by default), any LogException during logging is propagated to the calling application. |
|
Filter<? super LogEntry> |
getFilter()
returns null by default |
|
LogEntry |
getLast()
returns the last entry logged with this logger (while enabled and filter passed). |
|
LogWriter[] |
getWriters()
|
|
void |
ignoreLogExceptions()
sets a LogExceptionHandler that simply ignores any given LogException, so no Exception will be propagated to the calling application if logging fails. |
|
boolean |
includesStack()
returns true if a stack trace is produced when a Logger method creates a LogEntry (false by default) |
|
boolean |
isEnabled()
the logger only logs if the return value is true (which it is by default) |
|
boolean |
isResolveOriginIfMissing()
|
|
void |
log(Level level,
String message,
long time,
String sourceClass,
String sourceString,
Throwable thrown,
String threadName,
StackTraceElement[] stack,
Object[] parameters)
|
|
void |
log(Level level,
String message,
Object... parameters)
|
|
void |
log(LogEntry entry)
logs the entry by writing to the writers after checking whether the logger is enabled and the filter (if available) accepts the entry. |
|
void |
log(Object origin,
Level level,
String message,
Object... parameters)
|
|
void |
log(Object origin,
Level level,
Throwable thrown,
String message,
Object... parameters)
|
|
void |
log(Object origin,
String message,
Object... parameters)
|
|
void |
log(Object origin,
Throwable thrown)
|
|
void |
log(String message,
Object... parameters)
|
|
void |
log(Throwable thrown)
|
|
void |
log(Throwable thrown,
String message,
Object... parameters)
|
|
|
query(Class<T> requiredReturnType,
Object context)
returns the first embedded LogWriter that is also an instance of the given requiredReturnType or null |
|
void |
removeAllWriters()
|
|
boolean |
removeWriter(LogWriter writer)
removes the given writer from the list of log writers |
|
void |
setAllFrom(Logger logger)
copies the properties of the given object and applies them to this instance, so that its behavior in regards to the given object can be matched to the extend that the implementing class supports that behavior. |
|
void |
setEnabled(boolean flag)
allows to enable/disable this instance |
|
void |
setExceptionHandler(LogExceptionHandler handler)
|
|
void |
setFilter(Filter<? super LogEntry> filter)
|
|
void |
setIncludeStack(boolean on)
|
|
void |
setResolveOriginIfMissing(boolean flag)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Logger()
public Logger(LogWriter... writer)
public Logger(Logger logger)
| Method Detail |
|---|
public <T> T query(Class<T> requiredReturnType,
Object context)
throws IllegalArgumentException
query in interface QueryMechanismT - the required return typerequiredReturnType - specifies the return type that is needed for this operation;
if Object.class is given, any returned object is admissiblecontext - provides a context parameter for which the desired instance is to be returned.
Often (if no other meaningful context is required or applicable), it makes sense to pass a reference
to the calling object source; null may also be allowed
IllegalArgumentException - if the given requiredReturnType doesn't implement LogWriterpublic void setAllFrom(Logger logger)
Forgeable
setAllFrom in interface Forgeable<Logger>logger - the object whose behavior is to be copied to this instancepublic LogWriter[] getWriters()
public void addWritersFromLogger(Logger logger)
public boolean includesStack()
public void setIncludeStack(boolean on)
public boolean isResolveOriginIfMissing()
public void setResolveOriginIfMissing(boolean flag)
public boolean addWriter(LogWriter writer)
public boolean removeWriter(LogWriter writer)
public boolean containsWriter(LogWriter writer)
public void removeAllWriters()
public void closeAllWriters()
public void log(String message,
Object... parameters)
throws LogException
LogException
public void log(Level level,
String message,
Object... parameters)
throws LogException
LogException
public void log(Throwable thrown)
throws LogException
LogException
public void log(Throwable thrown,
String message,
Object... parameters)
throws LogException
LogException
public void log(Object origin,
String message,
Object... parameters)
throws LogException
LogException
public void log(Object origin,
Level level,
String message,
Object... parameters)
throws LogException
LogException
public void log(Object origin,
Throwable thrown)
throws LogException
LogException
public void log(Object origin,
Level level,
Throwable thrown,
String message,
Object... parameters)
throws LogException
LogException
public void log(Level level,
String message,
long time,
String sourceClass,
String sourceString,
Throwable thrown,
String threadName,
StackTraceElement[] stack,
Object[] parameters)
throws LogException
LogExceptionpublic boolean isEnabled()
isEnabled in interface Enabledpublic void setEnabled(boolean flag)
Enabled
setEnabled in interface Enabledpublic Filter<? super LogEntry> getFilter()
public boolean accept(LogEntry entry)
accept in interface Filter<LogEntry>getWriters()public void setFilter(Filter<? super LogEntry> filter)
public void setExceptionHandler(LogExceptionHandler handler)
public LogExceptionHandler getExceptionHandler()
ignoreLogExceptions()public void ignoreLogExceptions()
setExceptionHandler(LogExceptionHandler),
LogExceptionHandler.EXCEPTION_IGNORER
public void log(LogEntry entry)
throws LogException
getLast() while writing the entry,
a previous entry would be returned.
LogException - if a LogWriter throws a LogException during logging.
The exception handling can be controlled by setting
an LogExceptionHandler. If no LogExceptionHandler is
configured, the Exception is simply propagated to the
calling method.getFilter(),
isEnabled(),
ignoreLogExceptions(),
setExceptionHandler(LogExceptionHandler)public LogEntry getLast()
LoggerCachepublic void clearLast()
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||