[slf4j-dev] slf4j i8ln

Ceki Gulcu ceki at qos.ch
Sun Aug 23 19:38:51 CEST 2009


Hello Takeshi,

I have cloned your repo on my machine and tried to understand the code. Very 
nice work by the way! While I am starting to understand the possibilities 
offered by enums, I still do not completely understand how enums are more 
dynamic than resource bundles.

If at one point in time you decide to modify the contents of a field in a 
LogMessage enum, you still need to compile the enum and redeploy the recompiled 
version. The enem field contains annotations, indicating the desired logging 
level. The level of a logging statement can thus be changed by changing the 
level annotation. However, you still need to recompile and redeploy the enum.

In the existing logging paradigm, you would need to change the level of the 
logging statement by editing the java class containing the given logging 
statement and recompile, repackage and redeploy. Your approach may be a little 
more convenient (only one file needs to edited and compiled even if multiple 
levels needs to be changed). Are there are other advantages?

Takeshi Kondo wrote:
> 
> 
> I've developed initial thought of SLF4j's i18n extension.
> It was committed to my branch 
> (http://github.com/takeshi/slf4j/tree/master).
> 
> I've implemented 4 features as follows.
> 
> 1. Logger interface using enum.
> @see org.slf4j.i18n.I18NLogger
> 
> 2. Extension point to bind log id's enum to log message and level.
> @see org.slf4j.i18n.spi.LogLevelResolver
> @see org.slf4j.i18n.spi.LogMessageFormatResolver
> 
> 3. Resolving log message and log level from Annotation associated from 
> log id's enum.
> @see org.slf4j.i18n.impl.AnnotationLogLevelResolver
> @see org.slf4j.i18n.impl.AnnotationMessageFormatResolver
> 
> 4. Resolving log message and log level from ResourceBundle associated 
> with log id's enum.
> @see org.slf4j.i18n.impl.ResourceBundleLogLevelResolver
> @see org.slf4j.i18n.impl.ResourceBundleMessageFormatResolver
> 
> 
> For example:
> ----
> Log Message Definition
> ----
> public enum LogMessages {
> 
>     @Error("error message {}") // log level is bound to Error.
>     TEST0001,               
> 
>     @Message("waring message {}") // log level is not specified.
>     TEST0002
> 
> }
> 
> ----
> Logging
> ----
> 
> public static void main(String[] args) {
>     I18NLogger logger = I18NLoggerFactory.getLogger(LogMain.class);
> 
>     // write to error log , because LogMessages.TEST0001 is bound to 
> Error level.
>     logger.log(LogMessages.TEST0001, "xxxx");
>     logger.log(LogMessages.TEST0001, new NullPointerException());
>     
>     // write log as error level.
>     logger.error(LogMessages.TEST0002, "xxxx");
>     // write log as warn level.
>     logger.warn(LogMessages.TEST0002, new NullPointerException());
> }
> 
> 
> Takeshi Kondo
> 

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch



More information about the slf4j-dev mailing list