2

I'm currently developing a website for a school project, and I've run into a problem regarding logging. I want to log my stuff using logback. However, my wildfly server isn't recognizing my logback config-file (logback.xml).

Logback.xml is placed in

src/main/resources/logback.xml

My logback.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="fileAppender" class="ch.qos.logback.core.FileAppender">
    <file>myLogFile.log</file>
    <append>true</append>
    <encoder>
        <pattern>%d [%thread] %-5level  %logger{35} - %msg%n</pattern>
    </encoder>
</appender>

<root level="TRACE">
    <appender-ref ref="fileAppender" />
</root>
</configuration>

My pom.xml looks like this:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.6.6</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.0.7</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>1.0.7</version>
</dependency>

When writing logs i do this:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyClass {
  private static final Logger logger = LoggerFactory.getLogger(MyClass.class);

  public void someMethod(){
    logger.debug("Dummy debug message.");
    logger.info("Dummmy info message.");
    logger.warn("Dummy warning message.");
    logger.error("Dummy error message.");
  }
}

One should think you would get a file with input similar to this:

2014-11-18 02:10:13,295 [main] DEBUG  com.example.package.ClassName - Dummy debug message.
2014-11-18 02:10:13,295 [main] INFO   com.example.package.ClassName - Dummy info message.
2014-11-18 02:10:13,296 [main] WARN   com.example.package.ClassName - Dummy warning message.
2014-11-18 02:10:13,296 [main] ERROR  com.example.package.ClassName - Dummy error message.

I do not. Instead i get the following in my terminal:

[0m02:22:49,489 INFO  [com.example.package.MyClass] (default task-4) Dummy info message.
[0m[33m02:22:49,489 WARN  [com.example.package.MyClass] (default task-4) Dummy warning message.
[0m[31m02:22:49,490 ERROR [com.example.package.MyClass] (default task-4) Dummy error message.

This is also being stored in a serverlog at the following location:

/wildfly-8.1.0.Final/standalone/log/server.log

I'm also sure that my logback.xml is included in the class path. Its found here:

/target/classes/logback.xml

After creating and deploying a .war to my server, one should expect that my config file is used for logback; but it's not. Rather its the default wildfly-logger-format (or default logback perhaps? Either way; not my config) that's being used, and no file is being created.

I can even remove my logback.xml there's actually no difference. I can't for the life of me figure out whats wrong here. Why wont wildfly use the logback.xml specified in the class path? Any help would be greatly appreciated!

1 Answer 1

1

You need to exclude the server logging dependencies or remove the logging subsystem in a jboss-deployment-structure.xml.

The issue is slf4j will look for a binding likely finding the server provided binding to jboss-logmanager. You'll need to make sure the slf4j logging dependencies provided by the server aren't added to your deployment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.