Bookmark this page

Guided Exercise: Controlling Logging Levels

Manipulate the logging levels of a size rotating file handler, and deploy an application that uses this handler to log messages.

Resources
Files:

/home/student/AD248/labs/logging-levels/standalone

/home/student/AD248/labs/logging-levels

Application URL: http://localhost:8080/logtest
Resources /home/student/AD248/labs/logging-levels/logtest.war

Outcomes

You should be able to change the log levels of a handler and view application log messages in Red Hat JBoss Enterprise Application Platform (JBoss EAP).

This command verifies that the following statements are true:

  • JBoss EAP is installed at /opt/jboss-eap-7.4

  • The logtest.war application is available

[student@workstation ~]$ lab start logging-levels

Instructions

  1. Start the standalone JBoss EAP server.

    1. Start a JBoss EAP instance by using the /home/student/AD248/labs/logging-levels/standalone folder as the base directory.

      [student@workstation ~]$ cd /opt/jboss-eap-7.4/bin
      [student@workstation bin]$ ./standalone.sh \
      -Djboss.server.base.dir=/home/student/AD248/labs/logging-levels/standalone/
      ...output omitted...
      15:38:31,891 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990

      Wait for the server to finish starting before proceeding.

  2. Use the management CLI to configure the log handler and deploy the example application.

    1. In a new terminal window, start the management CLI.

      [student@workstation ~]$ cd /opt/jboss-eap-7.4/bin
      [student@workstation bin] ./jboss-cli.sh --connect
    2. Create the FILE_BY_SIZE_ROTATING log handler.

      [standalone@localhost:9990] /subsystem=logging/\
      size-rotating-file-handler=FILE_BY_SIZE_ROTATING/:add\
      (file={"path"=>"production-server.log",\
      "relative-to"=>"jboss.server.log.dir"},\
      formatter="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",\
      level=INFO,max-backup-index=3,name=FILE_BY_SIZE_ROTATING,\
      rotate-size=1m)
      {"outcome" => "success"}
    3. Deploy the logtest.war application.

      [standalone@localhost:9990] deploy \
      /home/student/AD248/labs/logging-levels/logtest.war
    4. Attach the rotating log handler to the package used by the application.

      [standalone@localhost:9990] /subsystem=logging/logger=com.redhat.training.view:add\
      (category=com.redhat.training.view,handlers=["FILE_BY_SIZE_ROTATING"])
      {"outcome" => "success"}
  3. Use the logtest application to generate logs of varying log levels and verify that the handler only processes logs at or below its configured log level.

    1. Navigate to http://127.0.0.1:8080/logtest/ to access the logtest application.

    2. Fill out the form by using the following values:

      FieldValue
      Level INFO
      Message INFO Log Level Test

      Click Submit to send the log message to the handler.

    3. Open a new terminal window to verify that the messages were logged by the application.

      [student@workstation ~]$ tail -f \
      /home/student/AD248/labs/logging-levels/standalone/log/production-server.log
      04:09:53,623 INFO  [com.redhat.training.view.LogTester] (default task-1) INFO Log Level Test
    4. Send more INFO messages from the application and verify that the messages appear in the log file.

    5. Use the application to send a log message with the DEBUG log level. Verify that the message does not appear in the log file.

      This is because the handler is configured for the INFO log level and below. The DEBUG level is higher than the INFO level in the logger hierarchy.

    6. Use the application to send a log message with the WARN log level. Verify that the message appears in the log file.

      This is because the WARN level is lower than the INFO level in the logger hierarchy.

  4. Change the log handler level and verify that the handler processes logs at or below its updated log level.

    1. In the management CLI, change the default log level of the FILE_BY_SIZE_ROTATING handler to DEBUG.

      [standalone@localhost:9990] /subsystem=logging/\
      size-rotating-file-handler=FILE_BY_SIZE_ROTATING:\
      write-attribute(name=level,value=DEBUG)
      {"outcome" => "success"}
    2. Use the application to send a log message with the DEBUG log level. Verify that the message appears in the log file.

      This is because the handler is now configured to process DEBUG and all levels below DEBUG in the logger hierarchy.

    3. Use the application to send a log message with the INFO log level. Verify that the message appears in the log file.

      This is because INFO is below DEBUG in the logger hierarchy.

    4. Use the application to send a log message with the TRACE log level. Verify that the message does not appear in the log file.

      This is because TRACE is above DEBUG in the logger hierarchy and the handler will not process messages at this level.

  5. Clean up the classroom environment.

    1. Use the management CLI to undeploy the logtest.war application.

      [standalone@localhost:9990 /] undeploy logtest.war
    2. Exit the management CLI.

      [standalone@localhost:9990 /] exit
    3. In its terminal window, stop the tail command by pressing Ctrl+C.

    4. Stop the instance of JBoss EAP by pressing Ctrl+C in the terminal window that is running JBoss EAP.

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish logging-levels

Revision: ad248-7.4-18a9db2