1

I have satndalone.xml with logging config, and pom.xml with slf4j dependency configured. Using lombok.extern.slf4j.Slf4j api annotations(@Slf4j) for logging in java classes.

The issue is the logs using this Slf4j are printing on console but not printing in the server.log File in wildfly server.

I have given logging config of standalone.xml (and also logging.properties whose configuration values will be from standalone.xml) and logging config of pom.xml

Logger in java class:

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class AuthenticateABC {
.
.
.
.
methodABC() {
   log.error("authenticateUser NoResultException = " + nre.getMessage());
}

Logging config from standalone.xml in wildfly server:

    <profile>
    <subsystem xmlns="urn:jboss:domain:logging:3.0">
        <console-handler name="CONSOLE" autoflush="true">
            <level name="ERROR"/>
            <formatter>
                <named-formatter name="COLOR-PATTERN"/>
            </formatter>
        </console-handler>
        <periodic-rotating-file-handler name="FILE" autoflush="true">
            <level name="TRACE"/>
            <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="ERROR"/>
        </logger>
        <logger category="org.hibernate">
            <level name="ERROR"/>
        </logger>
        <logger category="org.jboss">
            <level name="ERROR"/>
        </logger>
        <logger category="org.jboss.as.config">
            <level name="ERROR"/>
        </logger>
        <logger category="sun.rmi">
            <level name="ERROR"/>
        </logger>
        <root-logger>
            <level name="TRACE"/>
            <handlers>
                <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>

logging.properties:

loggers=sun.rmi,org.jboss.as.config,org.hibernate,org.jboss,com.arjuna

logger.level=TRACE
logger.handlers=FILE

logger.sun.rmi.level=ERROR
logger.sun.rmi.useParentHandlers=true

logger.org.jboss.as.config.level=ERROR
logger.org.jboss.as.config.useParentHandlers=true

logger.org.hibernate.level=ERROR
logger.org.hibernate.useParentHandlers=true

logger.org.jboss.level=ERROR
logger.org.jboss.useParentHandlers=true

logger.com.arjuna.level=ERROR
logger.com.arjuna.useParentHandlers=true

# Additional handlers to configure
handlers=CONSOLE


handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.level=ERROR
handler.CONSOLE.formatter=COLOR-PATTERN
handler.CONSOLE.properties=autoFlush,target,enabled
handler.CONSOLE.autoFlush=true
handler.CONSOLE.target=SYSTEM_OUT
handler.CONSOLE.enabled=true

handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.FILE.level=TRACE
handler.FILE.formatter=PATTERN
handler.FILE.properties=append,autoFlush,enabled,suffix,fileName
handler.FILE.constructorProperties=fileName,append
handler.FILE.append=true
handler.FILE.autoFlush=true
handler.FILE.enabled=true
handler.FILE.suffix=.yyyy-MM-dd
handler.FILE.fileName=C\:\\wildfly-10.1.0.Final\\standalone\\log\\server.log

formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%d{yyyy-MM-dd HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%e%n

formatter.COLOR-PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.COLOR-PATTERN.properties=pattern
formatter.COLOR-PATTERN.pattern=%K{level}%d{HH\:mm\:ss,SSS} %-5p [%c] (%t) %s%e%n

pom.xml

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.3.0.Final</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
        <type>zip</type>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.12</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.12</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging-processor</artifactId>
        <version>2.1.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging</artifactId>
        <version>3.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.18</version>
    </dependency>

when I configure standalone.xml <console-handler> log <level> to ERROR and <periodic-rotating-file-handler> log <level> to TRACE, I expect the debug log of slf4j log.debug("authenticateUser = " + currentUser); in my java code to be printed in server.log file, but this is printing on console.

2019-01-04 DEBUG [default task-8] (AuthenticateABC.java:98) - authenticateUser = APPUSER

I have tried several combinations of log levels and handlers, but still no luck, don't know what is wrong.

ddc
  • 885
  • 6
  • 12
  • Are you editing these files when the server is running? The console handler doesn't look assigned to anything so it should get nothing printed to it. Another possibility is you have a logging configuration file in your deployment. – James R. Perkins Jan 06 '19 at 21:29
  • No, I am not editing these files, when server running. I don't know where another logging config can be there in deployment, could you please tell me in which directory it can be in wildfly server. Thing is when ever I change the logging config like `log level` from `debug` to `error` or ` ` from `console` to `FILE` in the standalone.xml file, the values are getting into effect and the log content is changing accordingly, so I am thinking that I am working on the right configuration file. – ddc Jan 07 '19 at 09:52
  • @JamesR.Perkins Thanks, I found where the another logging configuration file is in my application. There is a 'log4j.properties` file in `src\main\resources` folder. This file contains wrong file path configurations `log4j.appender.file.File=XYZ.log`, due to which the log is being written in XYZ.log file located in wildfly bin directory. After changing this path to server.log `log4j.appender.file.File=${jboss.server.log.dir}/server.log` the log is writing into `server.log` file. – ddc Jan 07 '19 at 15:53
  • Ah yes that would do it. There is an attribute you can change to disable that. I'd also suggest using the web console or CLI to make changes as there would be no reason to shutdown the server first. – James R. Perkins Jan 07 '19 at 17:37
  • +1 I have single `wildfly server` in which I have to deploy multiple web applications, in this case, I believe I have to use different logging configuration file to each web application so that each application will have separate log file specific to that application. For this reason I am maintaining one more logging configuration file inside the application, along with `standalone.xml` config. – ddc Jan 10 '19 at 10:44
  • Have a look at [logging profiles](http://docs.wildfly.org/15/Admin_Guide.html#logging-profiles) as well. This would allow you to keep the configuration files out of a deployment. – James R. Perkins Jan 10 '19 at 17:05

0 Answers0