How can I log in to the console / server.log from within a jboss module?
Let's say I have a class:
public class MyClass {
private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
private boolean done = false;
public void doSomething() {
logger.info("Look ma, I'm logging!");
done = true;
}
public boolean isDone() {
return done;
}
}
If I want to log something from within a deployed artifact (e.g., MyWebProject.war
), all I have to do is:
Compile against slf4j-api
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<scope>provided</scope>
</dependency>
Deploy
./jboss-cli.sh -c "deploy MyWebProject.war"
And soon
2015-10-19 11:04:02,445 INFO [com.myCompany.MyClass] (default task-13) Look ma, I'm logging!
But I can not, by any means, get the same effect from within a jboss module.
Example: If MyWebProject.war
uses MyModule.jar
, and MyModule.jar
is deployed as a jboss module:
${jbossHome}/modules/com/mycompany/mymodule/main
|____ MyModule.jar
|____ module.xml
Module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.mycompany.mymodule">
<resources>
<resource-root path="MyModule.jar" />
</resources>
<dependencies>
<module name="org.slf4j" />
</dependencies>
</module>
If I move MyClass
to MyModule.jar
and use it in MyWebProject.war
I can see the side effects (e.g. isDone() == true
) but nothing is written to server.log
.
What am I forgetting? Do I need some other dependency besides slf4j?
Crosspost: Original question - SOen - How to log with slf4j from within a jboss module?