You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by jeffrey_chavis <Je...@jhuapl.edu> on 2003/10/03 17:43:41 UTC

log4j xml configuration

I am having problems getting log4j to configure from an XML file. 
When I use the xml file shown below, i get the following warning in 
java (1.4.1_02). Note: When I use a non-XML properties file it works 
just fine.

log4j:WARN No appenders could be found for logger 
(edu.jhuapl.latency.GNCSTlatencylog4j).

log4j:WARN Please initialize the log4j system properly.

Any ideas? Thanks in advance.

Here is the xml file
---------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
                     	   debug="true">

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

<!-- Rolling file Appender -->
	<appender name="R" 
class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="log/gncst.log"/>
		<param name="MaxFileSize" value="1000KB"/>
		<param name="MaxBackupIndex" value="5"/>
		<layout class="org.apache.log4j.PatternLayout">
  		     <param name="ConversionPattern"
                            value="%d{ISO8601} %-5p %C{2} [%t] (%F:%
L) - %m%n"/>
		</layout>
	</appender>

<!-- LogFactor5 appender -->
	<appender name="LF5_CLIENT" 
class="org.apache.log4j.lf5.LF5Appender">
		<param name="MaxNumberOfRecords" value="1000"/>
	</appender>

<!-- JDBC Appender -->
	<appender name="JDBC" 
class="org.apache.log4j.jdbcplus.JDBCAppender">
		<param name="url" 
value="jdbc:oracle:thin:@tofu:1521:gncst"/>
		<param name="username" value="gdba"/>
		<param name="password" value="gdba"/>
		<param name="sql"
                       value="INSERT INTO latency_log
(LATENCY_IDENTIFIER, EVENT, COMPONENT, PROCESSING_LEVEL, 
SECURITY_LEVEL, MESSAGE, TIMESTAMP) VALUES (@LATENCY_IDENTIFIER@, 
@EVENT@, @COMPONENT@, @PROCESSING_LEVEL@, @SECURITY_LEVEL@, 
@MESSAGE@, @TIMESTAMP@)"/>
		<param name="buffer" value="1"/>
		<param name="commit" value="Y"/>
		<layout class="org.apache.log4j.PatternLayout">
  		     <param name="ConversionPattern"
                            value="%d{ISO8601} %-5p %C{2} [%t] (%F:%
L) - %m%n"/>
		</layout>
	</appender>

<!-- Root debugger -->
	<root>
		<priority value="debug"/>
	        <appender-ref ref="stdout"/>
		<appender-ref ref="R"/>
		<appender-ref ref="LF5_CLIENT"/>
		<appender-ref ref="JDBC"/>
	</root>

</log4j:configuration>




---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: log4j xml configuration

Posted by Fabio Uechi <fa...@alexandria.cc>.
You have to invoke the DOMConfigurator.configure method instead
of the PropertyConfigurator one.

URL log4jURL = null;
try {
     log4jURL = getServletContext().getResource("/" +
configPath);
} catch (MalformedURLException murle) {
    //ignore...we check for null later
}
if (log4jURL != null) {
     DOMConfigurator.configure(log4jURL);
}

jeffrey_chavis writes: 
> OK, I added a file named log4j.xml to a directory in the classpath 
> and this works wonderfully. 
> 
> The next question is I want to use the PropertyConfigurator to load a 
> named config file. When I pass the PropertyConfigurator a non-xml 
> file it works, but if I pass it an xml file it does not. Is there 
> something I need to do in the PropertConfigurator to get it to load 
> an XML file 
> 
> Here is the code i use to pass the filename to the 
> PropertyConfigurator 
> 
> String userDir = System.getProperty("user.dir","test"); 
> String fileSeparator = System.getProperty("file.separator"); 
> String filename = userDir + 
> fileSeparator + 
> "config" + 
> fileSeparator + 
> "Sync_GNCST_Latency_config"; 
> 
> // use the Property Configurator to configure log file. 
> PropertyConfigurator.configure(filename); 
> 
> Jeff 
> 
> 
> 
> --------------------------------------------------------------------- 
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org 
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org 
> 
> 
--------------------------------------------------------------------------------
Get your free 15 Mb POP3 email @alexandria.cc
Click here -> http://www.alexandria.cc/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: log4j xml configuration

Posted by jeffrey_chavis <Je...@jhuapl.edu>.
OK, I added a file named log4j.xml to a directory in the classpath 
and this works wonderfully.

The next question is I want to use the PropertyConfigurator to load a 
named config file. When I pass the PropertyConfigurator a non-xml 
file it works, but if I pass it an xml file it does not. Is there 
something I need to do in the PropertConfigurator to get it to load 
an XML file 

Here is the code i use to pass the filename to the 
PropertyConfigurator 

    String userDir = System.getProperty("user.dir","test");
    String fileSeparator = System.getProperty("file.separator");
    String filename = userDir +
                      fileSeparator +
                      "config" +
                      fileSeparator +
                      "Sync_GNCST_Latency_config";

    // use the Property Configurator to configure log file.
    PropertyConfigurator.configure(filename);

Jeff



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: log4j xml configuration

Posted by Ceki Gülcü <ce...@qos.ch>.
At 12:11 PM 10/3/2003 -0500, you wrote:
>At 03:43 PM 10/3/2003 +0000, you wrote:
>>I am having problems getting log4j to configure from an XML file.
>>When I use the xml file shown below, i get the following warning in
>>java (1.4.1_02). Note: When I use a non-XML properties file it works
>>just fine.
>>
>>log4j:WARN No appenders could be found for logger
>>(edu.jhuapl.latency.GNCSTlatencylog4j).
>>
>>log4j:WARN Please initialize the log4j system properly.
>>
>>Any ideas? Thanks in advance.
>
>Try removing all appenders except for the console appender from the <root> 
>logger and see it works.  Reducing the extraneous variables will help 
>pinpoint the problem more efficiently.  Also, I assume you had put 
>log4j.properties in the classpath and let log4j load it automatically.  I 
>imagine you did the same for log4j.xml.  I think Log4j loads properties 
>files preferentially to XML files (I could be wrong here).

Actually, it's log4j.xml first and log4j.properties second. Of course, this 
does not help in hunting down the problem.


-- 
Ceki Gülcü

      For log4j documentation consider "The complete log4j manual"
      ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp

      import org.apache.Facetime;
      ApacheCon US 2003, 18-21 November http://apachecon.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: log4j xml configuration

Posted by Jacob Kjome <ho...@visi.com>.
At 03:43 PM 10/3/2003 +0000, you wrote:
>I am having problems getting log4j to configure from an XML file.
>When I use the xml file shown below, i get the following warning in
>java (1.4.1_02). Note: When I use a non-XML properties file it works
>just fine.
>
>log4j:WARN No appenders could be found for logger
>(edu.jhuapl.latency.GNCSTlatencylog4j).
>
>log4j:WARN Please initialize the log4j system properly.
>
>Any ideas? Thanks in advance.

Try removing all appenders except for the console appender from the <root> 
logger and see it works.  Reducing the extraneous variables will help 
pinpoint the problem more efficiently.  Also, I assume you had put 
log4j.properties in the classpath and let log4j load it automatically.  I 
imagine you did the same for log4j.xml.  I think Log4j loads properties 
files preferentially to XML files (I could be wrong here).  Given that, it 
is possible that there were no other log4j.properties files in the 
classpath other than yours, but there may have been another log4j.xml file 
in the classpath that might be overriding yours.  That's just a shot in the 
dark as to why it worked with the properties file and not the XML file.

BTW, you should use <level> rather than <priority>.

Jake


>Here is the xml file
>---------------------
>
><?xml version="1.0" encoding="UTF-8"?>
><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
>
><log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
>                            debug="true">
>
><!-- Console Appender -->
>         <appender name="stdout"
>class="org.apache.log4j.ConsoleAppender">
>                 <layout class="org.apache.log4j.PatternLayout">
>                      <param name="ConversionPattern"
>                             value="%d{ISO8601} %-5p %C{2} [%t] (%F:%
>L) - %m%n"/>
>                 </layout>
>         </appender>
>
><!-- Rolling file Appender -->
>         <appender name="R"
>class="org.apache.log4j.RollingFileAppender">
>                 <param name="File" value="log/gncst.log"/>
>                 <param name="MaxFileSize" value="1000KB"/>
>                 <param name="MaxBackupIndex" value="5"/>
>                 <layout class="org.apache.log4j.PatternLayout">
>                      <param name="ConversionPattern"
>                             value="%d{ISO8601} %-5p %C{2} [%t] (%F:%
>L) - %m%n"/>
>                 </layout>
>         </appender>
>
><!-- LogFactor5 appender -->
>         <appender name="LF5_CLIENT"
>class="org.apache.log4j.lf5.LF5Appender">
>                 <param name="MaxNumberOfRecords" value="1000"/>
>         </appender>
>
><!-- JDBC Appender -->
>         <appender name="JDBC"
>class="org.apache.log4j.jdbcplus.JDBCAppender">
>                 <param name="url"
>value="jdbc:oracle:thin:@tofu:1521:gncst"/>
>                 <param name="username" value="gdba"/>
>                 <param name="password" value="gdba"/>
>                 <param name="sql"
>                        value="INSERT INTO latency_log
>(LATENCY_IDENTIFIER, EVENT, COMPONENT, PROCESSING_LEVEL,
>SECURITY_LEVEL, MESSAGE, TIMESTAMP) VALUES (@LATENCY_IDENTIFIER@,
>@EVENT@, @COMPONENT@, @PROCESSING_LEVEL@, @SECURITY_LEVEL@,
>@MESSAGE@, @TIMESTAMP@)"/>
>                 <param name="buffer" value="1"/>
>                 <param name="commit" value="Y"/>
>                 <layout class="org.apache.log4j.PatternLayout">
>                      <param name="ConversionPattern"
>                             value="%d{ISO8601} %-5p %C{2} [%t] (%F:%
>L) - %m%n"/>
>                 </layout>
>         </appender>
>
><!-- Root debugger -->
>         <root>
>                 <priority value="debug"/>
>                 <appender-ref ref="stdout"/>
>                 <appender-ref ref="R"/>
>                 <appender-ref ref="LF5_CLIENT"/>
>                 <appender-ref ref="JDBC"/>
>         </root>
>
></log4j:configuration>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org