[slf4j-dev] slf4j i8ln

Takeshi Kondo takeshi.kondo at gmail.com
Sun Aug 23 07:32:04 CEST 2009


A non-text attachment was scrubbed...
Name: slf4j-i18n-1.5.9-SNAPSHOT.jar
Type: application/java-archive
Size: 29992 bytes
Desc: not available
URL: <http://qos.ch/pipermail/slf4j-dev/attachments/20090823/d3b53f6a/attachment.jar>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: slf4j-i18n-1.5.9-SNAPSHOT-sources.jar
Type: application/java-archive
Size: 14197 bytes
Desc: not available
URL: <http://qos.ch/pipermail/slf4j-dev/attachments/20090823/d3b53f6a/attachment-0001.jar>
-------------- next part --------------


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



More information about the slf4j-dev mailing list