Pako
Pako

Reputation: 439

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

Upvotes: 0

Views: 2712

Answers (3)

ddc
ddc

Reputation: 965

This may be old post, since I came across this post to solve my issue which is described above, someone in future can also read this. For this reason I wanted to share my answer here.

In my case I have followed this post https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/6.2/html/administration_and_configuration_guide/example_logging_profile_configuration and couple of other and created <logging-profile> in standalone.xml file in wildFly server and created MANIFEST.MF file manually in \src\main\resources\META_INF folder, then the log file got created but the log content is not writing inside of that.

The reason is my application is using maven for build config and creating manifest file.

If the application is using maven for build configurations or maven plugin to create manifest.mf file then you have to add the below information in your application's pom.xml file.

  • if the application is using maven for build configurations, then add below lines in pom.xml <build> <plugins> tag
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <archive>
                        <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin> 
  • if the application is using maven plugin to create manifest.mf file then add below lines in pom.xml <manifestEntries> i.e. in
<build> 
   <plugins> 
     <plugin> 
       <archive> 
        <manifestEntries> 
          <Logging-Profile>myAppLogProfile</Logging-Profile> 
        </manifestEntries>

after adding this, if you do mvn clean and mvn install then the Logging-Profile: myAppLogProfile line will be added to your MANIFEST.MF file in war file

Manifest-Version: 1.0
Logging-Profile: myAppLogProfile

after this when I redeploy it, the log file has log content in it.

Hope this helps someone.

Upvotes: 1

James R. Perkins
James R. Perkins

Reputation: 17840

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.

Upvotes: 2

Will Tatam
Will Tatam

Reputation: 572

Do not change the root-logger, but add a category that matches the package name you wish to debug

Upvotes: 0

Related Questions