Question

I'm having a problem with my logj2.xml being seen on my Windows7/64 box running Java 1.7.0_13/64. I'm trying to run the application using the NetBeans/64 7.2.1 IDE via the debugger.

log4j2.xml is sitting in my r:\ directory. The (user)classpath is ".;r:\". It is apparently not being seen, because when I look at the 'config.config.name' of the Logger in my debugger, it gives me the value of 'Default'. Also, I can't find the file specified in the log4j2.xml file anywhere, on any drive, of my machine. I've also looked for any new files containing the word 'default' on my machine, and can find none that are current.

So I suspect I'm doing 1 of 2 things wrong:

1) Setting my classpath incorrectly. 2) Putting my log4j2.xml file together incorrectly.

Any help would be appreciated. My keys are getting sticky from banging them with my forehead.

Here's the config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="debug" name="xxx" packages="" >
  <appenders>
      <RollingFile name="log" fileName="qqq.log"
           immediateFlush="true" filePattern="qqq-%d{yyyy-MM-dd}.log">
         <PatternLayout>
            <pattern>"%d{YYYY-MM-dd HH:mm:ss}   [%t]   %-5level   %logger{36} - %n%msg%n%n%n"</pattern>
         </PatternLayout>
         <Policies>
            <TimeBasedTriggeringPolicy />
            <SizeBasedTriggeringPolicy />
         </Policies>
         <DefaultRolloverStrategy max="92"/>
      </RollingFile>
  </appenders>
  <loggers>
     <root level="trace">
        <appender-ref ref="log"/>
    </root>
  </loggers>
</configuration>
Was it helpful?

Solution

Ok, got it. I've renamed this question to include NetBeans, because that was the gist of my problem.

As a review, it is required that the log4j2.xml file needs to go on the classpath. While I could affect the classpath in netbeans by adding jar files to the project, I didn't initially think about finding a config file on the classpath. Anyway, once I realized that, I played around a bit in project properties, and finally figured out that just adding the folder to the 'Compile-time libraries' dialog ( in this case "r:\" ) puts the config file on the classpath, and my logging works just like it should.

Whew!

Hope this helps someone.

OTHER TIPS

Thanks joe7pak, your posts were the last piece of the puzzle to solve my log4j properties problem in NetBeans. My problem required a couple extra steps that may help round this solution out.

First, I created a log4j.xml file in the src directory using the default xml from http://wiki.apache.org/logging-log4j/Log4jXmlFormat.

I then set the NetBeans VM options in Properties\Run to: -Dlog4j.debug. I noticed that a jar's (httpbuilder) log4j.xml file was being loaded by default instead of mine.

So I added the src folder to the compile time libraries in Properties\Libraries using your recommendation. However, it was still loading the log4j.xml file from the jar.

The final touch was to move the src folder to the top of the compile time libraries.

Thanks for your post and for answering yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top