Hi, I'be started usin log4j in one of my apps.  In order to use it i've 
made a jar file that contains the log4j itself, a Java Stub Class 
(Log.java) and a log4j-config,xml inside it. 
The problem is that, once i load the config file via domConfigurator and i 
instantiate a log object, appears a warning indicating that the logger 
doesn't have any appender configured..

The configuration part seems to work because the log file defined in the 
xml is created, but it's empty.

The config file looks as this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "dtds/log4j.dtd"> 
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>

        <appender name="File" class="org.apache.log4j.FileAppender">
            <param name="File"   value="A1.log" />
            <param name="Append" value="false" /> 
            <layout class="org.apache.log4j.PatternLayout">
                        <param name="ConversionPattern" value="%t %-5p 
%c{2} - %m%n"/>
            </layout> 
        </appender>

        <appender name="Console" class="org.apache.log4j.ConsoleAppender">
                <layout class="org.apache.log4j.PatternLayout">
                   <param name="ConversionPattern"
                          value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
                </layout> 
        </appender>

        <root>
           <priority value ="debug" />
           <appender-ref ref="Console" />
         <appender-ref ref="File" />
        </root>

</log4j:configuration>

Using this, the code in wich i create log4j is:

 private Logger logger;
 
    public Log(String userName) {
        if (log==null){
        try {
           String fichero = "/log4j-config.xml";
            DOMConfigurator domLog = new DOMConfigurator(); 
            Hierarchy hierarchy = new Hierarchy(new
                                RootCategory(Level.DEBUG));
           InputStream is = Log.class.getResourceAsStream(fichero); //we 
open the XML as an inputStream because it's inside the jar, not the 
filesystem

            domLog.doConfigure(is,hierarchy);
 
        } catch(Exception e) {
            e.printStackTrace();
 
        }
        logger = (Logger) Logger.getInstance(this.getClass().getName());
        }
        this.usuario=userName;
    }

I think the problem is related with the way i get the Logger instance, but 
i'm not sure

Reply via email to