Here's the complete initDatabase method ...

        public void initDatabase(String databaseFileConfig, String
nomDatabase) throws ApplicationException {

                try {
        
                        if (jdo == null) {
                                // Redirection des logs
                                Category cat =
Category.getInstance(this.getClass().getName());
                                Log4jStringWriter log4jWriter =
                                        new Log4jStringWriter(cat,
Priority.DEBUG);
                                Logger logger = new
Logger(log4jWriter).setPrefix("castor ");
                                jdo = new JDO();
                                ClassLoader loader =
this.getClass().getClassLoader();
                                jdo.setClassLoader(loader);
                                jdo.setLogWriter(logger);
                                jdo.setDatabaseName(nomDatabase);
        
jdo.setConfiguration(databaseFileConfig);
        
                                if( jdo == null ){
                                        throw new
ApplicationException("Objet JDO introuvable");
                                }
                        }
        
                } catch (Exception e) {
                        throw new ApplicationException("initDatabase : "
+ e.getMessage(), e);
                }
        }
}
___________________
CREDI RA
Sylvie Palluel

[EMAIL PROTECTED]
___________________



-----Message d'origine-----
De : SYLVIE PALLUEL [mailto:[EMAIL PROTECTED] 
Envoy� : mardi 17 f�vrier 2004 10:24
� : '[EMAIL PROTECTED]'
Objet : RE : [castor-dev] Log4j-Adapter for castor


Hi,

Here's a complete example.

May be that will help you.

Sylvie.



package xxx.xxx.util;

import java.io.StringWriter;

import org.apache.log4j.Category;
import org.apache.log4j.Priority;

/**
 *
 * <p>Titre : Log4jStringWriter</p>
 * <p>Description : Int�gration du logging de jdo Castor au logging
Log4j </p>
 * <p>Copyright : Copyright (c) 2002</p>
 * @author : John Freeborg
 * @version 1.0
 */
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);
    }
}


Package xxx.xxx.aaaa

import org.apache.log4j.Category;
import org.apache.log4j.Priority;
import org.exolab.castor.util.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import xxx.xxx.util.Log4jStringWriter;
 .

Reply via email to