JBoss server.log output customization

2019-08-12 15:03发布

I have developed a servlet that outputs the server.log file of my JBoss 7.1 for easier debugging.

What i want to do is to customize the output of JBoss and also display from which war each line of output is generated.

To understand better this is a sample output right now:

server log as a servlet

What i want is also to output something that will identify from which deployment this output is coming from.

After the URL in each output i noticed a number after the 7001 port that is different for each deployment, but don't know how to associate that with a war file....

Anyone has an idea how i can do that?

Thanks in advance

UPDATE

I found this on the web http://java.dzone.com/articles/configuring-logging-jboss about configuring JBoss but sadly is for another version. Here it explains how to have log4j create different log files per deployment. That would be the ultimate solution for me.

1条回答
贪生不怕死
2楼-- · 2019-08-12 15:32

First of all, it seems (from the content of your logs) you are using System.out.println and System.err.println.

If you switch your logging to slf4j, log4j, commons-logging and of course jboss-logging (thank you James) will be able to see what package you are logging from.

Once you use a proper logging facility you can filter by category by editing configuration file.

Also the logging will show more readable i.e. :

05:21:42,272 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)

I will assume you are using the standalone configuration in $JBOSS_HOME/standalone/configuration/standalone.xml

You need to find the logging subsystem

    <subsystem xmlns="urn:jboss:domain:logging:1.1">

and create a new appender of type periodic-rotating-file-handler:

        <periodic-rotating-file-handler name="APPLOG1">
            <formatter>
                <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
            </formatter>
            <file relative-to="jboss.server.log.dir" path="applog1.log"/>
            <suffix value=".yyyy-MM-dd"/>
            <append value="true"/>
        </periodic-rotating-file-handler>

Then add the filter:

         <logger category="com.yourapppackage">
            <level name="INFO"/>
            <handler name="APPLOG1"/>
        </logger>

That should do the work.

If I am not mistaken you can also create appenders and category filters from the administration console and the CLI

Regards

查看更多
登录 后发表回答