4

I have a WebApp that I develop using NetBeans 7.4. I deploy it on a Linux server running Tomcat 7.0.47.

I am trying to have a decent logging mechanism with slf4j and logback.

My project uses the following jars:

  • slf4j-api-1.7.6.jar
  • logback-classic-1.1.1.jar
  • logback-core-1.1.1.jar

My app is a SOAP server. At the head of the service class I put:

private static final String nameOfLogger = MatrixSoapService.class.getName();

private static final Logger soapLogger = LoggerFactory.getLogger(nameOfLogger);

then when I need to log something:

soapLogger.info("Init");

etc...

Ok. That's for the context.

My question is: how do I configure this to have rolling logs in my $CATALINE_HOME/conf folder for this application?

I thought I only needed to create a simple logback.xml file in the src folder of my webapp like this, but to no avail. I have no log generated.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>mySOAP - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
    </layout>
  </appender>
   
  <logger name="com.xxx" level="TRACE"/>
 
  <root level="debug">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>
Community
  • 1
  • 1
BxlSofty
  • 501
  • 4
  • 16
  • 3
    You haven't added a `FileAppender` so no wonder that no files are created. Your logs will currently be going to `catalina.log`. – Boris the Spider Feb 20 '14 at 21:14
  • Can someone explain me how to fix my config file above so that a dedicated file is created? – BxlSofty Feb 20 '14 at 22:07
  • 1
    The documentation for Logback is very good - read the section on [appenders](http://logback.qos.ch/manual/appenders.html) - specifically the part on the `RollingFileAppender`. – Boris the Spider Feb 20 '14 at 22:14
  • The main issue was that the location of that file was wrong. I put it now in `/webapps/your-app/WEB-INF/classes/` as explained here: http://stackoverflow.com/questions/20427307/where-to-put-logback-xml-in-tomcat – BxlSofty Feb 22 '14 at 09:56

1 Answers1

3

The main issue was that the location of that file was wrong. I put it now in

/webapps/your-app/WEB-INF/classes/

and at least the content of that logback.xml is used

BxlSofty
  • 501
  • 4
  • 16