I write a litte webapp in zk/spring. I tried in many different mode to activate logging (i read some post etc..) but without success.

1) I tried, for simplicity, automatic config with file log4j2.xml (like some examples read here)

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
    <File name="File" fileName="/tmp/stccGestioneGiri.log">
      <PatternLayout>
        <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
      </PatternLayout>
    </File>
  </Appenders>
  <Loggers>
    <Logger name="TestLog" level="trace">
      <AppenderRef ref="Console"/>
      <AppenderRef ref="File"/>
    </Logger>
    <Root level="info">
      <AppenderRef ref="Console"/>
      <AppenderRef ref="File"/>
    </Root>
  </Loggers>
</Configuration>

2) I put the xml file under WEB-INF directory

3) I write some very simple code in my appl

Logger logger = LogManager.getLogger(Menu.class.getName());
logger.trace("This is a trace message."); 
logger.debug("This is  a debug message."); 
logger.info("This is an info message."); 
logger.error("This is an error message");

but I cannot read in stdout trace/debug/info messages; and I cannot find my log file under /tmp or under {tomcat_path}/logs/

Someone can help me? Thanks

Luca

有帮助吗?

解决方案

The log4j2.xml file needs to be in the classpath. Is it located under WEB-INF/classes? Also, do you have both the log4j-core-2.0 and log4j-api-2.0 jar files in the classpath (WEB-INF/lib)? You need both these jars.

Your configuration looks correct. You can try setting <Configuration status="trace"> in the first line of the config to get log4j2-internal debug log messages on the console. This may help track down configuration problems.

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