11

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?

vvra
  • 2,832
  • 5
  • 38
  • 82

1 Answers1

22

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>
acm
  • 2,086
  • 3
  • 16
  • 34
Manu Artero
  • 9,238
  • 6
  • 58
  • 73
  • 3
    Having experimented with various configurations based on your approach, I finds the attribute, use-parent-handlers="false", is all that is needed, to disable logging into the server.log. – vvra May 27 '15 at 08:45
  • Upvoted. keeping that line in bold... but keeping too all the rest of the configuration if someone finds it helpful :) – Manu Artero May 27 '15 at 08:51
  • 2
    That's correct all that's needed is the `use-parent-handlers=false` to do what you're attempting to do. I'd also suggest not manually updating the XML, but using CLI or the web console to make logging changes as they can be done at runtime without the server shutdown or without having to restart the server. – James R. Perkins May 27 '15 at 15:48
  • Simply configuring a `...` as described is still compatible to wildfly 10. Great! – ChristophS Jul 27 '17 at 13:50