logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Douglas E Wegscheid <Douglas_E_Wegsch...@whirlpool.com>
Subject Re: xml config
Date Thu, 24 Feb 2011 19:08:06 GMT
and Jacob's other posting is also helpful:

I quote:


See more at...

(269) 923-5278 // Douglas_E_Wegscheid@whirlpool.com
"A wrong note played hesitatingly is a wrong note. A wrong note played 
with conviction is interpretation."

"Jacob Kjome" <hoju@visi.com> 
02/24/2011 12:06 PM
Please respond to
"Log4J Users List" <log4j-user@logging.apache.org>

"Log4J Users List" <log4j-user@logging.apache.org>

Re: xml config

"I place the xml file in my dist folder but it just does not work."

Is your "dist" folder in the running application's classpath?  If not, 
you can't expect it to possibly get picked up.

1.  Log4j looks for config files in the default package.  For instance, in 
webapp, this might be "WEB-INF/classes".  Or, it could be the root 
of a jar file.  As long as it isn't in a named package like 
then you are golden.  If you place the directory "/path/to/my/app" in the 
classpath, then you would place your config file in the directory 

2.  Log4j look for 2 different types of config files: XML files and 
files.  Because there are 2 possibilities, it has to prefer one over the 
other.  That is, it looks for one type and, if it doesn't find it, then 
for the other.  Log4j prefers XML files over Properties files.  That is, 
log4j.xml is found, it doesn't bother looking for log4j.properties.  
if log4j.xml is not found, then it looks for log4j.properties.  If you 
both in the classpath, only log4j.xml will be used.  In order to use 
log4j.properties, ensure that log4j.xml is NOT in the classpath.

3.  Just to emphasize the points in #1, your config file HAS to be in a 
directory or jar file that is in the running application's classpath.  If 
is not, then it won't be found by Log4j.  And if it is not in the default 
package, it also won't be found.


On Thu, 24 Feb 2011 11:38:38 -0500
 Bobby Richards <bobby.richards@gmail.com> wrote:
> 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" 
> %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: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org

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

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message