Right way to configure the log in Wildfly 8.2

Vijay Veeraraghavan picture Vijay Veeraraghavan · May 27, 2015 · Viewed 25k times · Source

I have confusion in setting up the log in Wildfly-8.2.0. Initially I had used my own logging system, with log4j.xml built into the WAR file, all worked very well. But, when I make any changes to the log configuration I need to redeploy the app to make the changes effect. So, I switched to the JBoss logger sub system. The below is configuration I did to the standalone.xml from the jboss-cli

/subsystem=logging/custom-handler=myplatform:add(class=org.apache.log4j.RollingFileAppender, module=org.jboss.log4j.logmanager, formatter="%d{.yyyy-MM-dd} %-5p [%c] (%t) %s%E%n", properties={MaxFileSize=1024000,maxBackupIndex=20,file="${jboss.server.log.dir}/myplatform-debug.log"})

so it added the below configuration in standalone.xml

            <custom-handler name="example" class="org.apache.log4j.RollingFileAppender" module="org.jboss.log4j.logmanager">
                <formatter>
                    <pattern-formatter pattern="%d{.yyyy-MM-dd} %-5p [%c] (%t) %s%E%n"/>
                </formatter>
                <properties>
                    <property name="MaxFileSize" value="1024000"/>
                    <property name="maxBackupIndex" value="20"/>
                    <property name="file" value="${jboss.server.log.dir}/ott-platform-log.log"/>
                </properties>
            </custom-handler>

And then a logger for this

<logger category="com.mycompany.project.module1">
  <level name="DEBUG"/>
    <handlers>
      <handler name="myplatform"/>
    </handlers>
</logger>

All works well, but all my application logs are logged into the server log too. And, in the console log too. I don't want this to happen, after all I have configured the logger separately for my project! How do I stop the server log my logs logging into the server.log? Or is there a way to use an appender for this? If so how?

Answer

Manu picture Manu · May 27, 2015

From the "clean" standalone.xml I do the following:

  1. Add a handler to the console:
<profile>
    <subsystem xmlns="urn:jboss:domain:logging:2.0">
        ...
        <console-handler name="CONSOLE_HANDLER">
            <level name="DEBUG"/>
            <formatter>
                <named-formatter name="ECLIPSE_PATTERN"/>
            </formatter>
        </console-handler>
        ...
  1. If you wish a log file:
<profile>
    <subsystem xmlns="urn:jboss:domain:logging:2.0">
       ...
       <periodic-rotating-file-handler name="MI_PROJECT_FILE_HANDLER" autoflush="true">
            <formatter>
                <named-formatter name="ECLIPSE_PATTERN"/>
            </formatter>
            <file relative-to="jboss.server.log.dir" path="myProject.log"/>
            <suffix value=".yyyy-MM-dd"/>
            <append value="true"/>
        </periodic-rotating-file-handler>
       ...
  1. The logger (same level as 1 and 2) notice the use-parent-handlers
<logger category="com.company.project" use-parent-handlers="false">
    <level name="DEBUG"/>
    <handlers>
        <handler name="MI_PROJECT_FILE_HANDLER"/>
        <handler name="CONSOLE_HANDLER"/>
    </handlers>
</logger>
  1. I've used a custom pattern (same level):
<formatter name="ECLIPSE_PATTERN">
    <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter> 
  1. Keep sure this:
<root-logger>
    <level name="INFO"/>
    <handlers>
        <handler name="CONSOLE"/>
        <handler name="FILE"/>
    </handlers>
</root-logger>