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 Steven Leija <St...@valtech.com> on 2001/08/21 20:17:34 UTC

Setting up XML configuration problems

Hello All,
 
I'm trying to set up my log4j configuration through an xml file.  My problem
is that it's not connecting to my xml file.  Can anyone please provide a
second and look at my code to see what my problem is below?  
 
I do appreciate any help!
 
Have a good one, 

Steven

//  My Logger File 

public class Logger
{
 private static final String CONFIG_FILE = "config.xml";
 
 public static final int LEVEL_INFO  = 0;
 public static final int LEVEL_DEBUG  = 1;
 public static final int LEVEL_WARN  = 2;
 public static final int LEVEL_ERROR  = 3;
 public static final int LEVEL_FATAL  = 4;
 
 static void init( String configFile )
 {
  DOMConfigurator.configure( CONFIG_FILE );
 }
 
 public static void log( String classType, String message )
 {
  log( classType, LEVEL_DEBUG, message );
 }
 
 public static void log( String classType, int logLevel, String message )
 { 
  Category cat = Category.getInstance( classType );
 
  Category root = Category.getRoot( );
  int loggingLevel = root.getPriority( ).toInt( );
 
  switch(loggingLevel)
  {
  case LEVEL_INFO:
   cat.info( message );
   break;
  case LEVEL_DEBUG:
   cat.debug( message );
   break;
  case LEVEL_WARN:
   cat.warn( message );
   break;
  case LEVEL_ERROR:
   cat.error( message );
   break;
  case LEVEL_FATAL:
   cat.fatal( message );
   break;
  }
 }
}

 
My XML File:

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

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/
<http://jakarta.apache.org/log4j/> ">
 
 <appender name="console" class="org.apache.log4j.FileAppender">
  <param name="File" value="System.out" />
  <param name="Append" value="false" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) -
%m%n"/>
  </layout>  
 </appender>
 
 <category name="org.apache.log4j.xml" >
  <priority value="INFO"  />
  <appender-ref ref="console"  />
 </category>

 <root>
  <priority value ="INFO" />
  <appender-ref ref="console" />
 </root>   

 </log4j:configuration>