13 Replies Latest reply: Jul 18, 2014 3:22 AM by David Balažic RSS

    Jboss AS 7 logging level change need restart?

    sarula bao Newbie

      Hi All,

       

      I saw in the Jboss 7 guide doc saying : Add a

       

      <logger category="com.test">

         <level name = "DEBUG">

      </logger>

       

      block will configure a logger for "com.test" category.

       

      Also saying it need no restart of the server.

       

      I tried this and logger is working fine except that it will not load by runtime, avery time I chage the log level i need to restart the server.

       

      Did I missing any other config?

       

      Thanks in advance.

       

      Sarula

        • 1. Re: Jboss AS 7 logging level change need restart?
          Brian Wallis Master

          If you make the change via the web admin interface (http://localhost:9990/) then a restart is not required, you could also do this via the cli (bin/jboss-cli.sh) but I'm not sure of the actual command to do it.

           

          The manual at https://docs.jboss.org/author/display/AS7/Admin+Guide#AdminGuide-ConfigurationFiles says

           

           

          The XML configuration files act as a central, authoritative source of configuration. Any configuration changes made via the web interface or the CLI are persisted back to the XML configuration files. If a domain or standalone server is offline, the XML configuration files can be hand edited as well, and any changes will be picked up when the domain or standalone server is next started. However, users are encouraged to use the web interface or the CLI in preference to making offline edits to the configuration files. External changes made to the configuration files while processes are running will not be detected, and may be overwritten.

           

           

          • 2. Re: Jboss AS 7 logging level change need restart?
            Brian Wallis Master

            I have been using the admin web interface for this but wondered how to add and remove loggers from the cli so I had a play.

             

            The following shows how I could add and remove a logger for org.jboss.as with a level of TRACE

             

            bwallis@master:~/JBoss/jboss-as-7.1.2.Final-SNAPSHOT> bin/jboss-cli.sh 
            You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
            [disconnected /] connect 172.16.95.131
            [domain@172.16.95.131:9999 /] ls /profile=full-ha/subsystem=logging/logger                  
            com.arjuna                               jacorb                                   jacorb.config                            org.apache.catalina.authenticator        org.apache.tomcat.util.modeler           org.jboss.as.clustering.infinispan
            org.jboss.as.clustering.web.infinispan   org.jboss.as.clustering.web.sso          sun.rmi
            [domain@172.16.95.131:9999 /]  /profile=full-ha/subsystem=logging/logger=org.jboss.as:add(level=TRACE)                
            {
                "outcome" => "success",
                "result" => undefined,
                "server-groups" => {"other-server-group" => {"host" => {"master" => {"server-three" => {"response" => {"outcome" => "success"}}}}}}
            }
            [domain@172.16.95.131:9999 /]  /profile=full-ha/subsystem=logging/logger=org.jboss.as:read-resource
            {
                "outcome" => "success",
                "result" => {
                    "filter" => undefined,
                    "handlers" => undefined,
                    "level" => "TRACE",
                    "use-parent-handlers" => true
                }
            }
            [domain@172.16.95.131:9999 /] ls /profile=full-ha/subsystem=logging/logger
            com.arjuna                               jacorb                                   jacorb.config                            org.apache.catalina.authenticator        org.apache.tomcat.util.modeler           org.jboss.as
            org.jboss.as.clustering.infinispan       org.jboss.as.clustering.web.infinispan   org.jboss.as.clustering.web.sso          sun.rmi
            [domain@172.16.95.131:9999 /]  /profile=full-ha/subsystem=logging/logger=org.jboss.as:remove          
            {
                "outcome" => "success",
                "result" => undefined,
                "server-groups" => {"other-server-group" => {"host" => {"master" => {"server-three" => {"response" => {"outcome" => "success"}}}}}}
            }
            [domain@172.16.95.131:9999 /] ls /profile=full-ha/subsystem=logging/logger                  
            com.arjuna                               jacorb                                   jacorb.config                            org.apache.catalina.authenticator        org.apache.tomcat.util.modeler           org.jboss.as.clustering.infinispan
            org.jboss.as.clustering.web.infinispan   org.jboss.as.clustering.web.sso          sun.rmi
            

             

             

            The effect of the add and remove is immediate without out any server restart.

            • 3. Re: Jboss AS 7 logging level change need restart?
              sarula bao Newbie

              Many thanks for your reply.

               

              I am on Windows and my app is migrating from jboss 4 to 7. Before migrate log4j was used for logging configuration and we used Appender element to change log level without restart.

               

              So I am wandering if there are similar way to do in Jboss 7. Or I have to configure log4j in jboss 7 ?

               

              Thanks

              Sarula

              • 4. Re: Jboss AS 7 logging level change need restart?
                Brian Wallis Master

                Hi Sarula,

                  No, no log4j configuration needed (or available). The equivilent is the handler configuration in the logging subsystem entry in either standalone.xml or domain.xml like so:

                 

                  <subsystem xmlns="urn:jboss:domain:logging:1.1">
                                <console-handler name="CONSOLE">
                                    <level name="TRACE"/>
                                    <formatter>
                                        <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                                    </formatter>
                                </console-handler>
                                <periodic-rotating-file-handler name="FILE">
                                    <formatter>
                                        <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                                    </formatter>
                                    <file relative-to="jboss.server.log.dir" path="server.log"/>
                                    <suffix value=".yyyy-MM-dd"/>
                                    <append value="true"/>
                                </periodic-rotating-file-handler>
                ...
                  </subsystem>
                

                 

                 

                You can edit this if the server is not running but to change it at runtime you just use either the admin web UI or the CLI.

                 

                ie: to set the console log level to TRACE using the CLI script (there is a version, jboss-cli.bat, for windows in the bin directory)

                 

                bwallis@master:~/JBoss/jboss-as-7.1.2.Final-SNAPSHOT>  bin/jboss-cli.sh
                [disconnected /] connect 172.16.95.131
                [domain@172.16.95.131:9999 /] /profile=full-ha/subsystem=logging/console-handler=CONSOLE:write-attribute(name=level,value=TRACE)
                {
                    "outcome" => "success",
                    "result" => undefined,
                    "server-groups" => {"other-server-group" => {"host" => {"master" => {"server-three" => {"response" => {"outcome" => "success"}}}}}}
                }
                

                 

                and then check the value

                 

                domain@172.16.95.131:9999 /] /profile=full-ha/subsystem=logging/console-handler=CONSOLE:read-resource                          
                {
                    "outcome" => "success",
                    "result" => {
                        "autoflush" => true,
                        "encoding" => undefined,
                        "filter" => undefined,
                        "formatter" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
                        "level" => "TRACE",
                        "target" => "System.out"
                    }
                }
                

                 

                 

                or just use the admin web UI as shown in the attached image (click on the edit button to change the log level)

                 

                Both these methods will make the change and persist it to the standalone.xml or domain.xml files.

                 

                (Note that the CLI examples I've given are all for a server running in domain mode, in standalone mode I think the path is a little different, the "/profile=full-ha" part is missing).

                • 5. Re: Jboss AS 7 logging level change need restart?
                  James Perkins Master

                  Correct about the standalone part for CLI.

                   

                  Note the handler must be able to log debug messages as well as the logger, e.g. category, in order for debug messages to appear. For example, I'll show standalone examples, you want to see debug messages from your application you need to add a logger for your application.

                   

                  /subsystem=logging/logger=com.example:add(level=TRACE)
                  

                   

                  By default the server.log is set to accept all levels so any logger created with a TRACE or DEBUG level will go in there. If you want to see TRACE messages on the console you need to change the consoles log level too.

                   

                  /subsystem=logging/console-handler=CONSOLE:write-attribute(name=level,value=TRACE)
                  

                   

                  This works the same on all platforms BTW.

                   

                  Changes to the XML while the server is running may very well get written over so it's highly suggested you don't make the changes when the server is running.

                   

                  For more information see the How To's on changing the log levels. At some point some more how to's/ recipes will be added to the documentation.

                   

                  On a side not too, as of 7.2.x deployments that contain a log4j or logging.properties configuration file will automatically be configured to work with that configuration when the application is deployed. The only caveat is that you cannot make changes to the deployments logging configuration via CLI, the web console or any other management operations.

                   

                  --

                  James R. Perkins

                  • 6. Re: Jboss AS 7 logging level change need restart?
                    David Balažic Newbie

                    Brian Wallis wrote:

                     

                    If you make the change via the web admin interface (http://localhost:9990/) then a restart is not required, you could also do this via the cli (bin/jboss-cli.sh) but I'm not sure of the actual command to do it.

                     

                    I used the web admin GUI to change the formatter pattern from "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n" to "%d{dd.MM.yyyy HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n".

                    The change was visible in standalone.xml immediately, but the actual logs were still using the old format (I waited more than a minute).

                     

                    Then I restarted jboss and the new format was used. Then I changed it back (again in admin GUI) and this time the change was applied to the logs without restarting

                     

                    Any idea what is happening?

                     

                    I use JBoss AS 7.1.1.

                     

                    Regards,

                    David

                     

                    PS: It seems whenever I change the formatter in the admin GUI, the logging reverts to the default format of "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n", no matter what I enter. Only after restart, the entered format is used. A bug?

                     

                    PPS: On the other hand, changing the log level in admin GUI works fine.

                    • 7. Re: Jboss AS 7 logging level change need restart?
                      Tomaz Cerar Master

                      Did you try in any newer version of AS?

                       

                      maybe 7.2 or WildFly8. there ware many many changes in logging subsystem since 7.1.1

                       

                       

                       

                      --

                      Tomaž

                      • 8. Re: Jboss AS 7 logging level change need restart?
                        David Balažic Newbie

                        No, it is on production.

                        • 9. Re: Jboss AS 7 logging level change need restart?
                          James Perkins Master

                          I couldn't get this to work either. Not sure what the issue is, but it's fixed in EAP 6.1 for sure I just tested. You could try running on EAP instead, JBoss Application Server Downloads - JBoss Community.

                           

                          --
                          James R. Perkins

                          • 10. Re: Jboss AS 7 logging level change need restart?
                            Olivier M Newbie

                            Could this be done through jmx ?

                            • 11. Re: Jboss AS 7 logging level change need restart?
                              Bui Van Nghiem Newbie

                              I also have the same question. I would like to change the log level from JMX. How can I do?

                              • 12. Re: Jboss AS 7 logging level change need restart?
                                Wolf-Dieter Fink Master

                                From AS7 the core is not longer based on MBeans.

                                The Configuration can be done via management interface (CLI console or programatic API) only

                                • 13. Re: Jboss AS 7 logging level change need restart?
                                  David Balažic Newbie

                                  It can also be done in the web console.