3 Replies Latest reply on Apr 17, 2017 3:06 PM by jamezp

    Logging with slf4j in @Schedule EJB Method

    ju113n_soc

      Hi,

       

      I am trying to log in a method triggered by a @Schedule annotation in my Singleton EJB :

       

      @Singleton
      public class SynchroChange {
      
          // inject slf4j logger with CDI producer
          @Inject @DefaultLogger private Logger LOGGER;
      
          @Schedule(hour = "*", minute = "*/15")
          public void doSomething() {
      
              // log with slf4j
              LOGGER.info("Hello World !!!");
          }
      }
      

       

      This EJB is packaged with Maven in a jar, alongside other war and jar modules. The whole app is packaged in an EAR and deployed with Wildfly 10.1.0.

       

      Then I followed this guide : Logging Configuration - WildFly 10 - Project Documentation Editor

      in order to configure the logger with a logging.properties file.

       

      My logging.properties is configured to log in a file, with a specific format at a specif level ...

      this config file is located in META-INF directory of the jar/ejb module after the build.

       

      Unfortunately, when the "doSomething()" method is triggered, the message is logged but without taking into account the config in logging.properties ...

       

      However, when I call "doSomething()" from an another module (from WS for example), the config works (the message is written in the file specified in logging.properties).

       

      How can I make the logging.properties works also in the case of a schedule triggered method ???Thanks

        • 1. Re: Logging with slf4j in @Schedule EJB Method
          jamezp

          What does your logging.properties look like? Where is the file located in your EAR?

           

          If you're using WildFly 10+ you can view what logging configuration your deployment is using with CLI.

          /deployment=NAME.ear/subsystem=logging:read-children-names(child-type=configuration)
          

           

          If you just see "default" that means the logging.properties is not being found in your deployment. You can execute the command on the sub-deployments or use the read-resource(recursive=true, include-runtime=true) if you want to see the resolved configuration.

           

          --

          James R. Perkins

          • 2. Re: Logging with slf4j in @Schedule EJB Method
            ju113n_soc

            Here is my logging.properties :

            loggers=com.cie.xyz
            
            logger.level=INFO
            logger.handlers=FILE,CONSOLE
            
            logger.com.cie.xyz.level=INFO
            logger.com.cie.xyz.useParentHandlers=true
            
            handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
            handler.CONSOLE.level=INFO
            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=INFO
            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\:\\Program Files\\JBoss\\wildfly-10.1.0.Final\\standalone\\log\\cgr.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] %m%n
            
            formatter.COLOR-PATTERN=org.jboss.logmanager.formatters.PatternFormatter
            formatter.COLOR-PATTERN.properties=pattern
            formatter.COLOR-PATTERN.pattern=%K{level}%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] %m%n
            

             

            This file is located in ear module in the directory src/main/application/META-INF.

            After compilation I have :

            xxx-ear

                 |-- META-INF

                      |-- application.xml

                      |-- logging.properties

                 |-- APP-INF

                 |-- xxx-ejb

                 |-- xxx-war

             

            I use wildfly 10.1.0 and when I execute this command :

            /deployment=xxx-ear-1.6.0.ear/subsystem=logging:read-children-names(child-type=configuration)
            

            I get :

            {
                "outcome" => "success",
                "result" => ["default"]
            }
            

             

            ... so my logging.properties is not found and I wonder why.

             

            If I put the logging.properties in the META-INF of the ejb module, it is recognized, the above command (with sub-deployment) return the path of the logging.properties. But my goal is to define logging in the whole application.

            • 3. Re: Logging with slf4j in @Schedule EJB Method
              jamezp

              Having the logging.properties in the EAR/META-INF should definitely work. I tested an EAR on WildFly 10.1.0.Final and got the following results:

              [standalone@localhost:9990 /] /deployment=ear.ear/subsystem=logging:read-children-names(child-type=configuration)  
              {
                  "outcome" => "success",
                  "result" => ["ear.ear/META-INF/logging.properties"]
              }
              
              [standalone@localhost:9990 /] /deployment=ear.ear/subdeployment=batch-chunk.war/subsystem=logging:read-children-names(child-type=configuration)
              {
                  "outcome" => "success",
                  "result" => ["ear.ear/META-INF/logging.properties"]
              }
              

               

              I can see messages being logged into the file I specified in the logging.properties as well.

              logger.level=INFO
              logger.handlers=FILE,CONSOLE
              
              
              handler.CONSOLE=org.jboss.logmanager.ha
              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=INFO
              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=${jboss.server.log.dir}/ear.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] %m%n
              
              
              formatter.COLOR-PATTERN=org.jboss.logmanager.formatters.PatternFormatter
              formatter.COLOR-PATTERN.properties=pattern
              formatter.COLOR-PATTERN.pattern=%K{level}%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] %m%n
              

               

              Maybe check the logging subsystem configuration. You'd want to check the add-logging-api-dependcies and use-deployment-logging-config attributes. Both should be set to true which is the default.

               

              You could turn on trace logging for org.jboss.as.logging as well. If the configuration file is being found you should see some log messages like the following:

              11:58:58,791 TRACE [org.jboss.as.logging] (MSC service thread 1-6) Scanning for logging configuration files.
              11:58:58,791 DEBUG [org.jboss.as.logging] (MSC service thread 1-6) Found logging configuration file: "/content/ear.ear/META-INF/logging.properties"
              11:58:58,792 TRACE [org.jboss.as.logging] (MSC service thread 1-6) Registering LogContext org.jboss.logmanager.LogContext@4fd916da for deployment ear.ear
              11:58:58,793 TRACE [org.jboss.as.logging] (MSC service thread 1-6) Scanning for logging configuration files.
              11:58:58,793 TRACE [org.jboss.as.logging] (MSC service thread 1-6) Registering LogContext org.jboss.logmanager.LogContext@4fd916da for deployment batch-chunk.war
              11:58:58,793 TRACE [org.jboss.as.logging] (MSC service thread 1-6) Scanning for logging configuration files.
              11:58:58,793 TRACE [org.jboss.as.logging] (MSC service thread 1-6) Registering LogContext org.jboss.logmanager.LogContext@4fd916da for deployment batch-jdbc-chunk.war
              11:58:58,793 TRACE [org.jboss.as.logging] (MSC service thread 1-6) Scanning for logging configuration files.
              11:58:58,794 TRACE [org.jboss.as.logging] (MSC service thread 1-6) Registering LogContext org.jboss.logmanager.LogContext@4fd916da for deployment batch-ejb.jar
              

               

               

              --

              James R. Perkins