Hi John,

thanks a lot for your help. I find that it can be very useful.
Unfortunately I tried it but it does not work...
I register my JDO object in JNDI (to use it with Session Beans) and when I
do it I get a java.rmi.UnmarshalException (with source exception
java.io.NotSerializableException on the Logger class and on the
LogInterceptor class).
I tried to make these classes implements the Serializable interface, but
this tricky workaround does not work, I get an
java.io.InvalidClassException (detailed message: java.io.PrintWriterMissing
no-arg costructor for class).
The only solution I found for the moment is... not register any Logger for
my JDO object, so it works fine (I forgot to tell you that I got these
exceptions also with the standard StringWriter class).
What do you think about?

Thanks a lot and have a nice day
Patrick



Patrick Herber


CSC Switzerland AG
Technologie und Softwareentwicklung
Binzm�hlestrasse 14
CH-8050 Z�rich
Phone: +41 (0)1 307 26 53
Fax: +41 (0)1 307 22 10
Mobile: +41 (0)79 211 35 01
E-Mail: [EMAIL PROTECTED]
http://www.ch.csc.com


                                                                                       
                               
                    "John Freeborg"                                                    
                               
                    <jfreeborg@softs        To:     [EMAIL PROTECTED]              
                               
                    witch.com>              cc:                                        
                               
                                            Subject:     [castor-dev] Integrate castor 
jdo logging with your regular  
                    26.11.2001 18:01        log4j logs in Tomcat                       
                               
                    Please respond                                                     
                               
                    to castor-dev                                                      
                               
                                                                                       
                               
                                                                                       
                               




Thought this might be useful for others.

I'm using Tomcat 4.0.1 and Castor JDO together.  My underlying servlet
app has a logging infrastructure using log4j.  Castor JDO doesn't use
log4j - it has a custom logging mechanism that is less flexible, but
straightforward.  I got tired of separately examining my log4j files and
my castor log files and trying to piece them together so I wrote a
little adapter class that puts my castor log into my log4j logs
seamlessly.  Here is the class and an example of how I init castor jdo
to use it.

Cheers,
 - John

--------- In the servlet init() method I do this:

        // Previously I've already initialized log4j
        // Get a log4j category reference so we can log things
        Category cat = Category.getInstance(this.getClass().getName());
        cat.info("Starting Servlet!");

        // We setup an adapter object (Log4jStringWriter) that the
Castor
        // JDO classes use for logging.  This allows us to redirect the
Castor
        // log output into our normal log4j logs.
        Log4jStringWriter log4jWriter = new Log4jStringWriter(cat,
Priority.DEBUG);
        Logger logger = new Logger(log4jWriter).setPrefix("castor");

        // Initialize Castor JDO
        String castorDatabaseFile =
config.getInitParameter("castorDatabaseFile");
        if (castorDatabaseFile == null)
        {
            throw new ServletException("Could not find
castorDatabaseFile init parameter in web.xml");
        }
        castorDatabaseFile =
config.getServletContext().getRealPath(castorDatabaseFile);
        jdo = new JDO();
        jdo.setLogWriter(logger);
        jdo.setConfiguration("file:///" + castorDatabaseFile);

---------- Here is the adapter class source:

public class Log4jStringWriter extends StringWriter
{
    private Category cat;
    private Priority pri;

    public Log4jStringWriter(Category cat, Priority pri)
    {
        super();
        this.cat = cat;
        this.pri = pri;
    }

    public Log4jStringWriter(Category cat, Priority pri, int
initialSize)
    {
        super(initialSize);
        this.cat = cat;
        this.pri = pri;
    }

    /**
     * Flush the stream.
     */
    public void flush()
    {
        super.flush();

        // Pass the buffer on to log4j
        cat.log(pri, super.toString());

        // Empty the buffer.
        super.getBuffer().setLength(0);
    }
}

-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
     unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to