I'm confused. I am using log4j 2 for logging and everything works fine, when I launch my program with eclipse. But after packing the sources to a jar there are no logs written to console or files.

Here's the jar's manifest:

Manifest-Version: 1.0
Built-By: s
Build-Jdk: 1.6.0_45
Class-Path: settings settings/log4j2.xml lib/poi-3.9.ja
 r lib/commons-codec-1.5.jar lib/mysql-connector-java-5.1.29.jar lib/l
 og4j-api-2.0-rc1.jar lib/log4j-core-2.0-rc1.jar
Created-By: Apache Maven 3.0.4
Main-Class: application.Start
Archiver-Version: Plexus Archiver

My log4j2.xml is here:

    <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} %C{1}.%M{1}:%L{1} - %msg%n"/>
    </Console>
    <RollingFile  name="app" fileName="log/app.log" bufferedIO="true" filePattern="log/app-%i.log.gz">
        <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} %C{1}.%M{1}:%L{1} - %msg%n"/>
        <Policies>
            <SizeBasedTriggeringPolicy size="500 KB"/>
      </Policies>
    </RollingFile > 
  </Appenders>
  <Loggers>
    <Logger name="app" level="trace">
        <AppenderRef ref="app" />
    </Logger>  
    <Root level="trace">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

All the other jars in lib are bound correctly and the application works well. What I'm doing wrong with log4j ?

有帮助吗?

解决方案

I have now a solution: The problem is my classpath. I've changed it from

Class-Path: settings

to

Class-Path: settings/

It suffices to state the directory where the xml is in.

其他提示

Try to start with -Dlog4j.debug=true (details). log4j will then print a lot of information about the configuration as it loads it.

With log4j 2, try <Configuration status="DEBUG">.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top