tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zlatan Kadragić" <aurel...@gmail.com>
Subject How to use a custom formater for org.apache.juli.FileHandler
Date Tue, 06 May 2008 10:28:52 GMT
I have
changed logging.properties file in conf directory so that i have
different log files for different web apps.
This is what i have changed/added to that file:

handlers = 1catalina.org.apache.juli.FileHandler,
2localhost.org.apache.juli.FileHandler,
3manager.org.apache.juli.FileHandler, 4admin.org.apache.juli.FileHandler,
5host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler,
6nomad.org.apache.juli.FileHandler
...

6nomad.org.apache.juli.FileHandler.level = FINE
6nomad.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
6nomad.org.apache.juli.FileHandler.formatter =
biz.zviz.util.logging.NomadLogFormatter
6nomad.org.apache.juli.FileHandler.prefix = nomad.

...

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/Nomad].level
= INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/Nomad].handlers
= 6nomad.org.apache.juli.FileHandler

Everything works O.K. if I do not set my custom formatter or if I set
java.util.logging.SimpleFormatter. But with custom formatter I loose all
LogRecords from /Nomad.

My formatter implementation is:
public class NomadLogFormatter extends java.util.logging.Formatter {
    public NomadLogFormatter() {
    super();
}

@Override
public String format(LogRecord logRec) {
    long time = logRec.getMillis();
    String msg = logRec.getMessage() == null ? "no message" :
logRec.getMessage();
    return String.format(FORMAT_STRING, time, msg);
}
public static final String FORMAT_STRING = "%1$tF %1$tT - %2$s%n";

}

I tried to put this class to common/classes, i have tried to put
NomadLogFormatter.jar to common/lib, also to include it to my web app, but I
always get this exception as first message when do restart Tomcat:

java.util.logging.ErrorManager: 4
java.lang.NullPointerException
at org.apache.juli.FileHandler.open(FileHandler.java:257)
at org.apache.juli.FileHandler.<init>(FileHandler.java:50)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at java.lang.Class.newInstance0(Class.java:350)
at java.lang.Class.newInstance(Class.java:303)
at
org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:396)
at
org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:341)
at
org.apache.juli.ClassLoaderLogManager.readConfiguration(ClassLoaderLogManager.java:236)
at java.util.logging.LogManager$2.run(LogManager.java:254)
at java.security.AccessController.doPrivileged(Native Method)
at
java.util.logging.LogManager.readPrimordialConfiguration(LogManager.java:252)
at java.util.logging.LogManager.getLogManager(LogManager.java:235)
at java.util.logging.Logger.<init>(Logger.java:201)
at java.util.logging.LogManager$RootLogger.<init>(LogManager.java:969)
at java.util.logging.LogManager$RootLogger.<init>(LogManager.java:966)
at java.util.logging.LogManager$1.run(LogManager.java:179)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.logging.LogManager.<clinit>(LogManager.java:156)
at java.util.logging.Logger.getLogger(Logger.java:254)
at
org.apache.commons.logging.impl.Jdk14Logger.getLogger(Jdk14Logger.java:152)
at org.apache.commons.logging.impl.Jdk14Logger.<init>(Jdk14Logger.java:53)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at
org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
at
org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
at
org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:53)


What is the problem? Please help me.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message