Table of Contents
The Extensions for the java.util.logging implementation (x4juli) provide more handlers, formatters and filters behind java.util.logging. x4juli provides a native implementation for a widely used logging facade, Jakarta Commons Logging and also for the new Simple Logging Facade for Java.
We are heavily working on tests and fixing bugs, but x4juli has still alpha status (December 2005, x4juli 0.6). Please use it in test environments and give us feedback.
You want miss any advantages of x4juli for new developments if you are using java.util.logging or one of the mentioned logging facades.
Developing a proprietary extension to x4juli is at your own risk. Until a major, production ready release ALL interfaces and classes are subject to change.
You can use java.util.logging and be sure that it will run with x4juli.
There are two cases:
You want to build it for JDK 1.4+, then consider using java.util.logging and you can be sure that it will run with x4juli.
You want to build it for JDK 1.4+ and user's choice for an logging API should be free, you should use an logging facade, i.E. Jakarta Commons,
still having the chance to use x4juli.
You want to build it compatible for older JDKs than 1.4, you should use an logging facade, i.E. Jakarta Commons
You can use x4juli. See section configuration, samples and tutorials for details.
You can use x4juli. See section configuration, samples and tutorials for details.
You can use x4juli. See section configuration, samples and tutorials for details.
You can use x4juli. See section configuration, samples and tutorials for details.
You can use x4juli for the container environment and you must stay at log4j for the application.
x4juli is a port of the backend part of log4j. It is a full port, so it does not use wrapper classes around the backend, instead it internally extends java.util.logging classes.
x4juli provides a native implementation for org.apache.commons.logging.Log interface and for the org.slf4j.Logger interface. x4juli uses the standard way of each facade to implement the corresponding factory. In case of Jakarta Commons Logging you still have to use the originally provided jar and put an config entry in the right place (System property or config.file). In case of slf4j you have to do nothing but remove all other sl4fj-xxxxx.jar files from the classpath. See section config for details.
The following sample shows the basic usage pattern and some features.
public class SimpleSample {
private static final Logger LOG = Logger.getLogger(SimpleSample.class.getName());
public String someMethod(String foo, int bar) {
LOG.entering("SimpleSample", "someMethod", new Object[]{foo, String.valueOf(bar)});
//doing something LOG.finer("Working with demo case");
try {
// doing more
File myFile = new File("demo.txt");
FileReader fr = new FileReader(myFile);
} catch (IOException e) {
LOG.log(Level.SEVERE, "Error occured accessing file",e);
} // End of catch block
String retValue = "Just demo case";
LOG.exiting("SimpleSample", "someMethod",retValue); return retValue;
} // End of Method
} // End of Class
First the actual logger is obtained and hold as static reference. The naming convention (as in most logging systems) is to use the full qualified class name for the logger.
The first log method (LOG.entering ....) is a utiliy method of an logger to log information when entering a new method. Use this with care and just where needed, because your log will be useless if flooded with this information. A good point to log the flow is the business facade of an application.
The second log method (LOG.finer ...) is an other utility method. You do not need to specifiy the level to log a simple message, it is implied by the method name.
The third log method (LOG.log(Level.SEVERE ....) is a basic log method: The Level is specified explicit, a message follows, the third parameter logs the exception which is caught.
The fourth and last method is similar to the first, just differing in the case, it is just for the end of a method.
There is no need for users to import anything of x4juli to use x4juli. x4juli is just an extension to the backend, so you can use it by putting it on the system classpath and use the correct configuration.
This is an x4juli FAQ. Please have a look at the project pages for their documentation regarding usage in user code.
This is one part different to all other logging frameworks and the one which has to be improved most.
Currently there is one sample (x4juli-standalone) delivered with x4juli. Please have a look at it for commented configuration.
At first you have to put the x4juli-x.x.jar on the system classpath. It is not enough(!) to have it on a depending classpath, i.E. in WEB-INF/lib in an webapplication. (This construction was invented by SUN for the java.util.logging API, it is not a construction of the developers of x4juli).
Second you have to specify that you want to use x4juli for logging: Put parameter -Djava.util.logging.manager=org.x4juli.X4JuliLogManager on the startup line (in your script, or corresponding config) for the JVM start.
Third you have to configure your loggers, handlers, formatters, look at the sample directory for a much better config!
#Declaring your handlers, each handler MUST start with an number!
#Handlers property must include ALL handlers, even when used with the root config ".handlers"
handlers = 1system.org.x4juli.handlers.FileHandler, 2testfoo.org.x4juli.handlers.FileHandler, java.util.logging.ConsoleHandler .handlers = 1system.org.x4juli.handlers.FileHandler, java.util.logging.ConsoleHandler
#Level of the root Logger
.level = FINEST
# Handler specific properties. # Describes specific configuration info for Handlers, here you have controll where log goes to and which level is needed.
# Each handler is configured with an formatter, and here you have to specifiy options for the corresponding formatter.
2testfoo.org.x4juli.handlers.FileHandler.level = FINEST
2testfoo.org.x4juli.handlers.FileHandler.filename = /etc/logs/testfoo.log
2testfoo.org.x4juli.handlers.FileHandler.name = 2testfoo
2testfoo.org.x4juli.handlers.FileHandler.formatter = org.x4juli.formatter.PatternFormatter
2testfoo.org.x4juli.formatter.PatternFormatter.pattern=[%d{ISO8601}]-[%p][%c]%m[%l]%n
1system.org.x4juli.handlers.FileHandler.level = INFO
1system.org.x4juli.handlers.FileHandler.filename = /etc/logs/system.log
1system.org.x4juli.handlers.FileHandler.name = 1system
1system.org.x4juli.handlers.FileHandler.formatter = org.x4juli.formatter.PatternFormatter
1system.org.x4juli.formatter.PatternFormatter.pattern=[%d{ISO8601}]-[%c][%p]%m%n
java.util.logging.ConsoleHandler.level = WARNING java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
# Logger specific properties, here you can control the different loggers:
org.foo.sample.level = FINEST org.foo.sample.handlers = 2testfoo.org.x4juli.handlers.FileHandler
org.foo.sample.child.level=INFO org.foo.another.package.level=SEVERE
There are two parts: At first you have to take action as described in "How do I configure x4juli?".
Second part: You have to make Jakarta Commons Logging use the x4juli JCLFactory. There are two possibilities: Specify a system property on your jvm startup (script): -Dorg.apache.commons.logging.LogFactory=org.x4juli.JCLFactory
or put in an commons-logging.properties file in your classpath with org.apache.commons.logging.LogFactory=org.x4juli.JCLFactory property line in the file.
x4juli delivers all necessary classes as specified on http://slf4j.org/faq.html section "Implementing the SLF4J API". You simply have to remove all sl4fj-xxxxx.jar from the classpath.
This description is based on Tomcat 5.5.12. First rename x4juli-x.x.jar to tomcat-juli.jar and put it in {tomcat_installation_directory}/bin (you have to overwrite the existing file).
Open catalina.sh or catalina.bat (Windows environment) in your favourite editor. Search for tomcat-juli.jar. Replace String "org.apache.juli.ClassLoaderLogManager" (without double quotes) with "org.x4juli.X4JuliLogManager" (without double quotes). This is also a good place to enable Jakarta Commons Logging native support, add "-Dorg.apache.commons.logging.LogFactory=org.x4juli.JCLFactory" (with double quotes in catalina.sh, without double quotes in catalina.bat) at the end of the line.
There are currently three samples delivered with x4juli. Please have a look at them for detailled step-by-step instructions.