[slf4j-dev] slf4j - Enhanced SimpleLogger
Erik Dick
erik.dick at balsol.com
Mon Oct 26 19:22:23 CET 2009
Hi all,
please find attached an enhanced variant of the current SimpleLogger
(as of slf4j v1.5.9 RC0). I would appreciate if you consider this
implementation for the standard release of SLF4J.
It differs from the current version such that it is enabled to read a
system property "org.slf4j.LogLevel" additionally and to set the log
level accordingly. If the system property is not set it behaves like
original version and logs on INFO level. The change should have no
performance penalty since it reads/interprets the system property only
once (during static initialization of SimpleLogger).
At the 'productive' classes I have only changed the class
SimpleLogger.java. A much larger change set you will find at the test
classes. I did that to ensure that all the changes that I have done do
not harm the overall contract of the implementation
SilentPrintStream has been changed so that it can record the most
recent line that has been printed to System.err.
InvocationTest has been changed so that it basically tests now the
SimpleLoggerFactory only; actually the singleton approach for getting
the logger. All other tests have been reworked and improved.
You will find in the package "org.slf.impl" the new test cases:
SimpleLoggerAbstractTest
SimpleLoggerDefaultTest
SimpleLoggerTraceTest
SimpleLoggerDebugTest
SimpleLoggerInfoTest
SimpleLoggerWarnTest
SimpleLoggerErrorTest
SimpleLoggerAbstractTest is not intended to be executed but in fact
contains 95% of the executed tests (including the reworked tests from
the previous InvocationTest). The test strategy is to execute the
different specializations of SimpleLoggerAbstractTest. Their main task
is to setup the test environment (setting the log level) and
performing basic checks. Functionality is tested by executing the
derived tests from the SimpleLoggerAbstractTest base class. Please
note that the individual SimpleLogger<Level>Test shall be executed in
their 'own' VM instance. If not respecting this, the test will fail
because the system property will never be re-read and such the log
level will not be set as required by the different test cases (except
for the first one being executed).
You will notice that the SilentPrintStream.getLastRecordedLine() (in
conjunction with recordingOn()/recordingOff()) is used to intercept
the output of the logger and compare it to the expected output. By
doing this not only the successful call but also the successful
message creation can be checked.
Please let me know your thoughts on this...
Best regards,
Erik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: slf4j-simple.tar.bz2
Type: application/x-bzip2
Size: 10530 bytes
Desc: not available
URL: <http://qos.ch/pipermail/slf4j-dev/attachments/20091026/61867d31/attachment.bin>
More information about the slf4j-dev
mailing list