Writeup of what I did in late January 2017 in order to configure logging in JBoss EAP 6.2.
Based on my travails, when it comes to logging in JBoss EAP6.2 there are three distinct options:
The above options are discussed in the respective sections below. Note that JBoss EAP 6.2+ and JBoss EAP 7.x use Log4j 1.2.16 (source).
This is the simplest approach of all. Under this approach all of your output is given by System.out.println statements which are going to find their way into the server.log file (e.g. in standalone/log/server.log). There is however a catch: Apparently there is a bug in JBoss to the effect that if a log4j.xml or logging.properties file is present on the classpath (typically in WEB-INF/classes) then these System.out.println logging statement will not be logged on the console, server.log, or test.log. They will simply vanish. According to a JBoss developer I spoke to this bug was fixed in EAP 6.2.3.
I also posted a question in SO about this mysterious disappearence of System.out.println messages and the same JBoss developer confirmed the issue (more or less) and suggested a workaround that might not require removal of logging.properties files. Namely, that I "just add a jboss-deployment-descriptor.xml and exclude the logging subsystem from processing your deployment". I tried that I solution as well but it didn't work.
As noted, JBoss EAP 6.2+ and JBoss EAP 7.x use Log4j so you can directly use logger.info and it works out of the box. Just be sure to compile your sources against a compatible version of Log4j (in other words pull the right Ivy dependency). Also, you only need the Log4j jars for the compilation stage. In both this and the next approach there is no reason (in fact you shouldn't) bundle the Log4j jar in the deployment WAR (e.g. in WEB-INF/lib). The output of all statements ending up in both the console and file server.log. You do not need to configure any additional logging in standalone-full.xml. Below is what I've used which is only trivially modified with respect to the default configuration bundled in EAP 6.2.0:
In this approach, since there is no log4j.xml file bundled with our WAR (see next section), we have no problem with the System.out.println statements as well, i.e. they all appear both in the console and server.xml
If we also want our logging to end up in a separate file as well we can issue the following CLI commands (source), e.g. for packages under mjb44:
/subsystem=logging/file-handler=my-app:add(append=true, autoflush=true, file={relative-to=jboss.server.log.dir, path=myapp.log}) /subsystem=logging/logger=mjb44:add(level=INFO, handlers=[my-app])
Issuing the above commands on the CLI:
$ ./bin/jboss-cli.sh You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands. [disconnected /] connect [standalone@localhost:9999 /] /subsystem=logging/file-handler=my-app:add(append=true, autoflush=true, file={relative-to=jboss.server.log.dir, path=myapp.log}) {"outcome" => "success"} [standalone@localhost:9999 /] /subsystem=logging/logger=mjb44:add(level=INFO, handlers=[my-app]) {"outcome" => "success"} [standalone@localhost:9999 /]… results in the following standalone.xml:
… the effect is the following:
By including a log4j.xml file in tha classpath (typically in WEB-INF/classes), you can issue Logger#info statements in your application that end up in some application-specific log file (not server.log).
NB: as in the previous approach, there is no reason to provide the Log4j jars in WEB-INF/lib. The JBoss server provides its own Log4j implementation in a module (in fact it is based on a fork of Log4j as they had to tweak something). Theoretically it should be possible to provide your own Log4j jar in WEB-INF/lib and include a jboss-deployment-structure.xml in META-INF to disable the JBoss own Log4j module as described here but I didn't have much luck with this approach.
E.g. I've confirmed that the following log4j.xml sends logger.info output to file cas-auth.log.
However, even though the above logger has a ConsoleAppender attached to it, no logger.info output is seen in either the console or in server.log (maybe a JBoss EAP 6.2.0 bug?)
Also, I have been advised against using a console appender in my own logger in this thread. The gist is:
I'd also advise against using the ConsoleAppender as it could result in deadlocks unless you disable the console-handler on the server.… and:
With regards to using the ConsoleAppender. The issues is you'd have two different log managers writing to the same output stream. In most cases it should work, it's just not a good practice to have two different objects writing to the same output stream.