Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java Open Source > Apache Tomcat
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Apache Tomcat General discussion of the Apache Tomcat servlet container. For discussions specific to the Professional Apache Tomcat book, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Apache Tomcat section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 6th, 2008, 06:04 AM
Registered User
 
Join Date: May 2008
Location: Belgrade, , Yugoslavia.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Setting formatter to org.apache.juli.FileHandler

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:
Code:
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:
Code:
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:
Code:
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.

Reply With Quote
  #2 (permalink)  
Old January 12th, 2011, 05:54 AM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

because initialize the formatter is at the starting time of tomcat , your class don't loaded by tomcat . solution is:
create a jar include your custom class (simple jar). then modify the catalina.sh , add the new jar to classpath.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
org.apache.jasper.JasperException:The value for th Lijin Apache Tomcat 1 January 18th, 2007 07:05 PM
Chapter 19 error of: Cannot find bean: "org.apache keeotee BOOK: Beginning JavaServer Pages 1 April 23rd, 2006 08:17 AM
Exception creating bean of class org.apache.struts chandseetare Apache Tomcat 0 May 14th, 2005 07:22 AM
org.apache.struts.* bongo76 Apache Tomcat 1 April 18th, 2004 05:06 AM
org.apache.strut.util.GenericDataSource elbicho JSP Basics 1 August 23rd, 2003 03:55 AM



All times are GMT -4. The time now is 05:04 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.