javaloggingwildflyjboss-loggingjboss-cli

Wildfly Logging Profile Setting ( logger.debug("test") )


I would like to create a profile for my application's logs

I need to use logger.debug() but if I put down in the standalone.xml file DEBUG I get too many lines

from <level name="INFO"/> to <level name="DEBUG"/>

.....................
    <subsystem xmlns="urn:jboss:domain:logging:3.0">
        <console-handler name="CONSOLE">
            <level name="DEBUG"/>
            <formatter>
                <named-formatter name="COLOR-PATTERN"/>
            </formatter>
        </console-handler>
        <periodic-rotating-file-handler name="FILE" autoflush="true">
            <formatter>
                <named-formatter name="PATTERN"/>
            </formatter>
            <file relative-to="jboss.server.log.dir" path="server.log"/>
            <suffix value=".yyyy-MM-dd"/>
            <append value="true"/>
        </periodic-rotating-file-handler>
        <logger category="com.arjuna">
            <level name="WARN"/>
        </logger>
        <logger category="org.jboss.as.config">
            <level name="DEBUG"/>
        </logger>
        <logger category="sun.rmi">
            <level name="WARN"/>
        </logger>
        <root-logger>
            <level name="DEBUG"/>
            <handlers>
                <handler name="CONSOLE"/>
                <handler name="FILE"/>
            </handlers>
        </root-logger>
        <formatter name="PATTERN">
            <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
        </formatter>
        <formatter name="COLOR-PATTERN">
            <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
        </formatter>
    </subsystem>
......................

I can create a profile that enables only debug logging of my application?

I created my profile and add in my MANIFEST.MF but it does not work

<logging-profiles>
   <logging-profile name="accounts-app-profile">
       <console-handler name="CONSOLE">
           <level name="DEBUG"/>
           <formatter>
              <named-formatter name="COLOR-PATTERN"/>
            </formatter>
       </console-handler>
       <file-handler name="ejb-trace-file">
           <level name="DEBUG"/>
           <file relative-to="jboss.server.log.dir" path="ejb-trace.log"/>
       </file-handler>
       <logger category="com.company.accounts.ejbs">
            <level name="DEBUG"/>
            <handlers>
                <handler name="ejb-trace-file"/>
            </handlers>
       </logger>
       <formatter name="COLOR-PATTERN">
           <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
       </formatter>
</logging-profile>

MANIFEST.MF

Manifest-Version: 1.0
Logging-Profile: accounts-app-profile

Call the Logger

final static Logger logger = Logger.getLogger("com.company.accounts.ejbs");

logger.debug("debug");
logger.info("info");

the file ejb-trace.log creates but does not write inside


Solution

  • A logging profile should not be required for what you're attempting to do. Assuming the category com.company.accounts.ejbsand assuming you want messages from your application to be logged into their own file the following CLI commands will

    /subsystem=logging/file-handler=ejb-trace-file:add(level=DEBUG, file={relative-to=jboss.server.log.dir, path=ejb-trace.log}, autoflush=true)
    /subsystem=logging/logger=com.company.accounts.ejbs:add(level=DEBUG, handlers=[ejb-trace-file], use-parent-handlers=false)
    

    If you also want the messages logged to the console handler or the server.log you can remove the use-parent-handlers=false attribute or set it to true.