I have a Java EE application that consists in EAR, WAR and EJB packages.
I have configured logback
by defining a @Produces
method in an EJB class, like so:
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
@Named
@Singleton
public class LoggerProducer {
@Produces
public Logger produceLogger(InjectionPoint injectionPoint) {
return LoggerFactory.getLogger(injectionPoint.getMember()
.getDeclaringClass().getName());
}
}
This works fine, injecting the interface with
@Inject
private Logger logger;
and logging with
logger.error("This is the error");
I have these dependencies in my pom.xml
:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
Now, I'm trying to include a logback.xml
file to the deployment, I added it to the EJB classpath:
<?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>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
But it doesn't work, it logs with the standard/default format.
I added the following jboss-deployment-structure.xml
file to the EJB/META-INF folder to exclude logging:
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
But it doesn't work either. If I put the jboss-deployment-structure.xml
in EAR/META-INF I get the following error at startup (pointing to the WAR classes only):
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Logger with qualifiers @Default
Where to put the logback.xml
file? How to configure the jboss-deployment-structure.xml
file and where to put it?