I guess I just do not understand log4j very well. I have spent the
past two days searching and reading the mailing list but just cannot
come up with an answer.
I am using Netbeans for development and I cannot understand where to
put my log4j.xml file, nor can I seem to figure out the concept.
I have created the simplest project, I have tried the Properties
loader but from what I have read it seems that log4j looks for the
log4j.xml file:
public class Main {
static Logger logger = Logger.getLogger(Main.class);
static Properties properties = new Properties();
static FileInputStream fis;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
logger.info("info");
logger.debug("debug");
logger.warn("warn");
}
}
I added log4j.xml into the src folder:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
Document : logging.xml
Created on : February 23, 2011, 12:34 PM
Author : bobby
Description:
Purpose of the document follows.
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %5p
%c{1}:%L - %m%n"/>
</layout>
</appender>
<appender name="file" class="org.apache.log4j.FileAppender">
<param name="File" value="/home/bobby/test.log"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%t
%-5p %c{2} - %m%n"/>
</layout>
</appender>
<root>
<priority value="info"/>
<appender-ref ref="console"/>
</root>
</log4j:configuration>
I can only seem to get this to act properly when I "clean and build".
Which makes no sense to me, the whole point of a config file is to
change before run, but I am only getting the desired result if the
code is essentially burned in.
Further more, when I try to distribute my jar I place the xml file in
my dist folder but it just does not work.
At this point I am just beyond frustration, any help would be
appreciated. I realize that this is the most basic of problems and I
apologize.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]