Listeners are
the last step in logging. Listeners receive
formatted message and a
LogMeta (see
below) to construct the final message. The final message is then handed
off to the underlying logging framework. (See
integration.)
A LogMeta is
a small object that contains meta-data for the final log statement.
At minimum this contains the expected
Date
(timestamp), and a
Severity. LogMeta
instances are created by
LogMetaProvider
objects which are used by Logger implementations.
Listeners most commonly follow the
adapter
pattern, usually sending the log message to the underlying logger
framework. Bug Listeners can take other forms, such as
JLogViewer.
Listener implementations may use a
MessageFormatter to simplify
creating the final message.
|
Listeners |
Included |
There are also some Listener implementations included in that
package. These can be used to help build a custom Listener, or to
write to some non-standard storage system.
One useful example would be to use a StreamListener with a
CipherOutputStream
to create a log that may contain confidential information.
Listeners can also be used for more than just writing directly to
a file or stream. For example, Listeners can be used to control the
flow of log messages. The
FailSafeListener
is designed to handle unreliable Listeners. The FailSafeListener
takes two Listeners, a primary and a backup Listener. If the primary
Listener throws an exception, the log message is logged to the backup
Listener.
|
Supplemental |
Below are implementations for well-know logging frameworks. These
implementations are not part of the core package because they depend
on external libraries -- the logging framework in question.
The code here is intended to be copied directly into your
code and customized to your needs. This code is also part of the
sources package if you wish to download
all of them at once.
If there is no Listener implementation for your preferred logger
framework, implementing one is very simple.
|
LoggerRegistry |
Logahawk also provides a
LoggerRegistry
interface that mimics the behavior of LoggerFactory (and similarly
named classes) found in
log4j,
SLF4J,
Commons Logging,
and other logger frameworks. These classes provide convenient methods
for finding the appropriate Logger for a given Class.
There is one significant difference between of Logahawk's
LoggerRegistries and other logger framework's equivalents --
LoggerRegistry is an interface and all members are non-static. That
means you have the option of creating multiple LoggerRegistry
instances, and configuring & sharing them in application specific
ways. This allows for the possibility of creating Loggers at run-time,
or Loggers whose formatting is customized to the requesting object.
The use of a LoggerRegistry is optional -- Logahawk does not require
their usage. (For simple applications they may be overkill.)
|
Included |
There are some LoggerRegistry implementations included with Logahawk:
|
Supplemental |
Below are LoggerRegistry implementations for well-know logging
frameworks. These implementations are not part of the core package
because they depend on external libraries -- the logging framework
in question.
The code here is intended to be copied directly into your
code and customized to your needs. This code is also part of the
sources package if you wish to download
all of them at once.
If there is no LoggerRegistry implementation for your preferred
loggerframework, please use the code above to build your own
implementation.
|