Hey
Mark,
I changed the file to an absolute value, but when
I run my test, no output is given. It's as if I didn't have anything in my
main method.
Any other suggestions?
Steven
-----Original
Message-----
From: Mark Womack [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 21, 2001 1:54 PM
To: 'LOG4J Users Mailing List'
Subject: RE: Setting up XML configuration problems
From: Mark Womack [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 21, 2001 1:54 PM
To: 'LOG4J Users Mailing List'
Subject: RE: Setting up XML configuration problems
What error are you getting? You might want to make the CONFIG_FILE a system property, that way you can change it at runtime. My guess is that "config.xml" is not a valid path to the file. You might need to fully qualify it like "file:c:/config.xml".Also, just as a note, where you assign an int value to your LEVEL_* constants, instead of using a value like 0, 1,2, etc, you might want to use the built in int values from the defined Priority classes like this:public static final int DEBUG = Priority.DEBUG_INT;That way you can use the value to map it to the defined Priority later, like this:public void log(int priority, Object message) {
category.log(Priority.toPriority(priority), message);
}It helps you avoid the switch statement. But you seem to have info at a lower priority than debug, so using the defined priorities may not work too well for you...-Mark-----Original Message-----
From: Steven Leija [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 21, 2001 11:18 AM
To: '[EMAIL PROTECTED]'
Subject: Setting up XML configuration problemsHello 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/">
<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>