On a Dual-Core Intel CPU clocked at 3.2 GHz, running the
@@ -229,7 +230,7 @@
href="xref-test/org/slf4j/profiler/NestedProfilerDemo2.html">NestedProfilerDemo2
-
[omitted]
+
[omitted]
17 public class NestedProfilerDemo2 {
18
19 static Logger logger = LoggerFactory.getLogger(NestedProfilerDemo2.class);
@@ -255,7 +256,7 @@
39 // stop and log
40 profiler.stop().log();
41 }
-42 }
+42 }
The output generated by this example will depend on the logging
environment, but should be very similar to the output generated by
@@ -276,7 +277,7 @@
logback configuration disabling logging from profilers, and only
profilers
-
package com.test;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -449,13 +450,13 @@ public class TestService {
logger.exit(key);
return key;
}
-}
+}
This test application uses the preceding service to generate
logging events.
-
package com.test;
+
package com.test;
public class App {
public static void main( String[] args ) {
@@ -464,7 +465,7 @@ public class App {
service.retrieveMessage();
service.exampleException();
}
-}
+}
The configuration below will cause all output to be routed to
target/test.log. The pattern for the FileAppender includes the
@@ -472,7 +473,7 @@ public class App {
pattern are critical for the log to be of value.
Here is the output that results from the Java classes and configuration above.
@@ -596,7 +597,7 @@ java.lang.ArrayIndexOutOfBoundsException: 3
occurs an EventData object should be created and populated. Then call EventLogger.logEvent(data)
where data is a reference to the EventData object.
-
import org.slf4j.MDC;
+
import org.slf4j.MDC;
import org.apache.commons.lang.time.DateUtils;
import javax.servlet.Filter;
@@ -666,10 +667,10 @@ public class RequestFilter implements Filter
public void destroy() {
}
-}
-
+}
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World");
}
-}
+}
a typical transformation would be similar to: (imports omitted)
-
public class LoggingHelloWorld {
+
public class LoggingHelloWorld {
final static Logger _log = LoggerFactory.getLogger(LoggingHelloWorld.class.getName());
public static void main(String args[]) {
@@ -781,7 +781,7 @@ public class MyApp {
_log.info("< main()");
}
}
-}
+}
which in turn produces the following result when run similar to
"java LoggingHelloWorld 1 2 3 4":
diff --git a/slf4j-site/src/site/pages/faq.html b/slf4j-site/src/site/pages/faq.html
index ae8d2fe5..586acf49 100644
--- a/slf4j-site/src/site/pages/faq.html
+++ b/slf4j-site/src/site/pages/faq.html
@@ -935,33 +935,12 @@ logger.debug("The new entry is {}.", entry);
-
No. SLF4J does not offer any particular support for
- I18N. However, nothing prevents you from implementing i18n
- support around the SLF4J API.
-
-
As suggested by Sebastien Davids in bug report
- 50, a possible pattern might be:
-
-
class MyClass {
-
- ResourceBundle bundle = ResourceBundle.getBundle("my.package.messages");
- Logger logger = LoggerFactory.getLogger(MyClass.class);
-
- void method() {
- if (logger.isWarnEnabled()) {
- MessageFormat format = new MessageFormat(bundle.getString("my_message_key"));
- logger.warn(format.format(new Object[] { new Date(), 1 }));
- }
- }
-}
-
-
Where my_message_key is defined as
-
my_message_key=my text to be i18n {1,date,short} {0,number,00}
A discussion
+ on the slf4j-dev mailing list spawned an open-source project
+ called CAL10N or Compiler
+ Assisted Localization. As its name indicates, CAL10N
+ focuses on the issue of localization/internationalization in Java
+ applications.
+
+
+
The org.slf4j.cal10n package which ships with
+ slf4j-ext-${project.version}.jar adds an extremely thin
+ layer on top of CALI0N to offer localized logging.
+
+
+
Once you have a handle on an IMessageConveyor
+ instance, you can create a LocLoggerFactory,
+ which in turn can create a LocLogger
+ instances capable of doing localized logging.
+
+
+
+
Let assume that you have defined localized message your
+ application. In accordance with the CAL10N's philopshopy, you have
+ the declared the keys for those messages in the enum type
+ Production.
It is assumed that you have created appropriate bundle file for
+ the various locales "en_UK" and "ja_JP" as appropriate. Then, you
+ can instantiate a IMessageCoveyor, inject it into a
+ LogLoggerFactory, retreive multiple
+ LogLogger instances by name and log away, as the next
+ sample code illustrates.
+
+
+
+
import java.util.Locale;
+
+import org.slf4j.cal10n.LocLogger;
+import org.slf4j.cal10n.LocLoggerFactory;
+
+import ch.qos.cal10n.IMessageConveyor;
+import ch.qos.cal10n.MessageConveyor;
+
+public class MyApplication {
+
+ // create a message conveyor for a given locale
+ IMessageConveyor messageConveyor = new MessageConveyor(Locale.JAPAN);
+
+ // create the LogLoggerFactory
+ LocLoggerFactory llFactory_uk = new LocLoggerFactory(messageConveyor);
+
+ // create a locLogger
+ LocLogger locLogger = llFactory_uk.getLocLogger(this.getClass());
+
+
+ public void applicationStart() {
+ locLogger.info(Production.APPLICATION_STARTED);
+ // ..
+ }
+
+ public void applicationStop() {
+ locLogger.info(Production.APPLICATION_STOPPED);
+ // ...
+ }
+}
+
+
Assuming the resource bundle production_jp.properties
+ exists, and the underlying logging framework is enabled for the
+ info level, log messages in Japenese will be output.
+
+
+
Note that a LogLogger is a regular SLF4J logger
+ with additional methods supporting localization.
SLF4J version 1.5.9 consist of bug fixes and minor
enhancements. It is totally backward compatible with SLF4J version
- 1.5.8. However, based on the CAL10N
- project support for internationalization was added to the
- slf4j-ext module.
+ 1.5.8. However, the slf4j-ext module ships with a new package called
+ org.slf4j.cal10n which adds localized/internationalized logging
+ support as a thin layer built upon the CAL10N API.
-
+
+