1

We're working on a migration of our application from WebSphere to JBoss EAP 6.4. I read on the Internet that since JBoss EAP 6.x, JBoss use its own logging framework called JBoss Logging instead of log4j previously.

We have already a log4j.properties file for application specific logs, which store logs in separate files according the log level (log-error.log, log-info.log, ...), but actually, they are also logged in the console and in the server.log file.

In the one hand, we would like application logs to be logged only with our existing log4j.properties configuration file, but also prevent them to be logged in server.log and console too.

In the other hand, we would like server specific logs to be logged with JBoss Logging framework, so in the server.log and in the console.

To sum up, we want to go from :

application logs + server logs => server.log/console + separate file logs

To this :

application logs => seperate file logs
server logs => server.log/console

Does somebody know how to achieve this ? Does anyone have already configured a JBoss server in a similar way ?

Thanks you,

Regards.

Fabien LH
  • 76
  • 1
  • 8

3 Answers3

2

Don't understand why but log4j also logs in stdout so JBoss Logging catch these logs and appends them again to JBoss console and server.log like this :

2017-08-08 15:14:20,304 INFO [stdout] <<My log4j log message>>.

I succeeded for the moment to prevent this by adding that code to standalone.xml file :

<logger category="stdout" use-parent-handlers="false">
    <level name="OFF"/>
</logger>

Isn't this a bad practise ?

Thanks,

Fabien LH
  • 76
  • 1
  • 8
  • If anything writes to `System.out` then it won't be logged. That would be the only issue. – James R. Perkins Aug 08 '17 at 20:37
  • Don't think it will be a problem, use of System.out is pretty discouraged in our application, but in case of, do you think I can declare a stdout logger in my log4j.properties file ? Something like _log4j.logger.stdout = INFO, outAppender_ ? Just to be sure that we don't loose logs and to locate System.out calls in order to remove them. – Fabien LH Aug 09 '17 at 14:43
  • Probably not. JBoss EAP replaces `System.setOut()` and `System.setErr()` with streams backed by a logger. This is in case someone writes to one of those streams and the console stream is discarded. – James R. Perkins Aug 09 '17 at 18:40
1

If you include a log4j.proeprties file in the WAR/WEB-INF/classes or EAR/META-INF it should just work. If you're seeing application specific logging in all places then my guess would be you have a console appender configured in your log4j.properties file.

James R. Perkins
  • 16,800
  • 44
  • 60
  • After removing the console appender in my log4j properties file, it still does not work. Any ideas ? – Fabien LH Aug 07 '17 at 09:56
  • Is it a WAR or EAR deployment? Are you using log4j as your logging framework? – James R. Perkins Aug 07 '17 at 15:22
  • It's an EAR deployment. Yes, we are. We use log4j with an home-made logging layer, which call log4j logging methods with additional log information aggregation. – Fabien LH Aug 08 '17 at 15:06
  • Don't understand why but log4j also logs in stdout so JBoss Logging catch these logs and processes them again by appending them in JBoss console and server.log like this : `INFO [stdout] <>` – Fabien LH Aug 08 '17 at 15:09
  • So if you see the `[stdout]` logs and are using a `ConsoleApppender` then it looks like JBoss EAP is seeing your logging configuration. JBoss EAP does wrap `stdout` and `stderr` in loggers. – James R. Perkins Aug 08 '17 at 15:46
  • Please see my reply. – Fabien LH Aug 08 '17 at 17:00
1

I have spent a few days figuring this out, and I think I have something that works. I am using EAP 6.4.

First, the solution mentioned above about adding code to standalone.xml makes the output from my solution described below more easy to read in the console. If you don't do that step, you get some extra line feeds in the console.

What I did is create a log4j.xml file, but I did NOT call it log4j.xml. For my 2 applications, I called it servicelog4j.xml. This means that JBoss will not find it.

Then when I am creating the log4j logger, I do the following (this is in a static method for my class called Log4jLogger):

public static Logger getLogger(Class aClass) {
    ClassLoader classLoader = Log4jLogger.class.getClassLoader();
    InputStream log4JStream = classLoader.getResourceAsStream("servicelog4j.xml");
    if (log4JStream != null) {
        new DOMConfigurator().doConfigure(log4JStream, LogManager.getLoggerRepository());
    }

    Logger log = Logger.getLogger(aClass);
    return log;
}

Now, the file servicelog4j.xml is in the resources folder of my Eclipse project, so that when the application is deployed, it will get copied to WEB-INF/classes/servicelog4j.xml.

The contents of that file are a standard log4j file. I have a standard file appender and a console appender. The file appenders for each application point to different files.

To have debugging code for just my classes appear in the console (and in the file), I place the following in servicelog4j.xml (since all my code is in the package com.mycompany.mypackage):

  <logger name="com.mycompany.mypackage">
      <level value="debug" />
      <appender-ref ref="CONSOLE" />
  </logger>
  <root>
      <priority value ="info" />
      <appender-ref ref="FILE" />
  </root>

With the above configuration, I get all messages in the Eclipse console as well as the file. If I just remove the <logger> section, then the debug messages go nowhere, which is what I'd want in production.

Irv
  • 540
  • 4
  • 13