Log4J Problem

Hi all,

I am trying to create a logging feature into my two simple java code and face with the foll problem.Please let me know how to get access to the Logger object that I have created in code1 to code2

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Java Code 1

import org.apache.log4j.Level;

import org.apache.log4j.Logger;

import org.apache.log4j.SimpleLayout;

import org.apache.log4j.FileAppender;

import org.apache.log4j.xml.DOMConfigurator;

public class simpandfile {

public static Logger logger = Logger.getLogger(simpandfile.class);

public static void main(String args[]) {

simpandfile hi= new simpandfile();

DOMConfigurator.configure("sudarson.xml");

logger.debug("Here is some DEBUG");

logger.info("Here is some INFO");

logger.warn("Here is some WARN");

logger.error("Here is some ERROR");

logger.fatal("Here is some FATAL");

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

Java code 2

public class simpandfile1{

public static void main(String args[]) {

// I am trying to access the same Logger Object Here

logger.debug("Here is somefdfdf DEBUG");

//This doesnt seem to work

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

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="appender" class="org.apache.log4j.FileAppender">

<param name="File" value="output1.txt"/>

<param name="Append" value="true"/>

<layout class="org.apache.log4j.PatternLayout">

<param name="ConversionPattern" value="%d [%t] %p - %m%n"/>

</layout>

</appender>

<root>

<priority value ="debug"/>

<appender-ref ref="appender"/>

</root>

</log4j:configuration>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

Output

Output1.txt

2005-08-13 11:54:46,545 [main] DEBUG - Here is some DEBUG

2005-08-13 11:54:46,545 [main] INFO - Here is some INFO

2005-08-13 11:54:46,545 [main] WARN - Here is some WARN

2005-08-13 11:54:46,545 [main] ERROR - Here is some ERROR

2005-08-13 11:54:46,545 [main] FATAL - Here is some FATAL

[2448 byte] By [sudarsona] at [2007-10-1 23:41:06]
# 1
Logger.getLogger(String) can be used to retreive a previously created logger.just call Logger.getLogger() with the same String name, I think it is the same for Logger.getLogger(Class);
--jubs--a at 2007-7-15 15:31:19 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 2

Topic seems to be continued in a separate thread:

http://forum.java.sun.com/thread.jspa?threadID=662956

@OP: Which topic do you want to continue on? It's not cool to have duplicates going on. I for one don't want to have to have to keep track of all your open threads to see what other answers you've been given before providing mine. It was not nice of you to duplicate this.

warnerjaa at 2007-7-15 15:31:19 > top of Java-index,Archived Forums,Debugging Tools and Techniques...