Java – the correct way to configure logs in wildfly 8.2
I'm setting up wildfly-8.2 0's log was confused Initially, I used my own log system, with log4j built into the war file XML, these are very good However, when I make any changes to the log configuration, I need to redeploy the application for the changes to take effect So I switched to JBoss recorder subsystem The following is my from JBoss cli to standalone XML configuration
/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 in standalone The following configuration has been added to the 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>
Then there is a recorder
<logger category="com.mycompany.project.module1">
<level name="DEBUG"/>
<handlers>
<handler name="myplatform"/>
</handlers>
</logger>
Everything is fine, but all my application logs are also logged into the server log This is also true in the console log I don't want to do this. After all, I have configured recorders for my project separately! How to stop the server log and log in to the server log? Or is there a way to use appender? If so
Solution
From "clean" standalone In XML, I do the following:
>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>
...
>If you want log files:
<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>
...
>The logger (at the same level as 1 and 2) noticed the use of the – parent handler
<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>
>I used a custom mode (same level):
<formatter name="ECLIPSE_PATTERN">
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
>Please ensure that:
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
