Bookmark this page

Guided Exercise: Configuring Logging Handlers

Create a size rotating file handler and deploy an application that uses this handler to log messages.

Resources
Files: /home/student/AD248/labs/logging-handlers
Application URL: http://localhost:8080/logtest
Resources

/home/student/AD248/labs/logging-handlers/logtest.war

/home/student/AD248/labs/logging-handlers/add_sizerotating_log.cli

Outcomes

You should be able to create a size rotating file handler and view log messages generated by the application in the Red Hat JBoss Enterprise Application Platform (JBoss EAP) server log files.

Before beginning the guided exercise, run the following command:

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

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

Instructions

  1. In a terminal window, start the standalone JBoss EAP server.

    1. Use the following command to start a JBoss EAP instance by using the provided 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-handlers/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 a management CLI script file to create a size-rotating-file-handler and deploy the logtest.war file.

    1. In a new terminal window, review the add_sizerotating_log.cli file.

      [student@workstation ~]$ cat \
      /home/student/AD248/labs/logging-handlers/add_sizerotating_log.cli
      batch
      /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)
      /subsystem=logging/logger=com.redhat.training.view:add\
      (category=com.redhat.training.view,handlers=["FILE_BY_SIZE_ROTATING"])
      deploy /home/student/AD248/labs/logging-handlers/logtest.war
      run-batch

      The batch script configures the logging subsystem to use the handler called FILE_BY_SIZE_ROTATING. This handler captures all of the logs generated by the category com.redhat.training.view, which represents a Java package where the logging source code is executed. It captures all of the logs generated with the INFO level in a file called /home/student/AD248/labs/logging-handlers/standalone/log/production-server.log.

      After the log file reaches 1 MB in size, the logging subsystem rotates the log file to a new log file with a numbered suffix. It creates a maximum of three (3) log files before the contents of the log files are overwritten in an iterative manner.

      Finally, the script deploys the logtest application. It is a Java web application with all of the source code in the com.redhat.training.view package.

    2. Run the management CLI script.

      [student@workstation ~]$ cd /opt/jboss-eap-7.4/bin
      no output expected
      [student@workstation bin]$ ./jboss-cli.sh -c --file=/home/student\
      /AD248/labs/logging-handlers/add_sizerotating_log.cli
      The batch executed successfully

      If the batch script fails, one troubleshooting technique is to manually run each command individually. In this way, the source of the error is more-easily found.

    3. Verify that the handler was added successfully.

      [student@workstation bin] ./jboss-cli.sh --connect
      [standalone@localhost:9990] /subsystem=logging/\
      size-rotating-file-handler=FILE_BY_SIZE_ROTATING:read-resource
      {
          "outcome" => "success",
          "result" => {
              "append" => true,
              "autoflush" => true,
              "enabled" => true,
              "encoding" => undefined,
              "file" => {
                  "relative-to" => "jboss.server.log.dir",
                  "path" => "production-server.log"
              },
              "filter" => undefined,
              "filter-spec" => undefined,
              "formatter" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
              "level" => "INFO",
              "max-backup-index" => 3,
              "name" => "FILE_BY_SIZE_ROTATING",
              "named-formatter" => undefined,
              "rotate-on-boot" => false,
              "rotate-size" => "1m",
              "suffix" => undefined
          }
      }
  3. Verify and observe the server handling the log messages generated by the application.

    1. In a web browser, navigate to http://127.0.0.1:8080/logtest/ to access the logtest application.

    2. Fill out the form with the following values:

      FieldValue
      Level INFO
      Message Test INFO Msg

      Click Send Log Messages to send the log message to the handler you created previously.

    3. In a new terminal window, view the most recent log messages in the /home/student/AD248/labs/logging-handlers/standalone/log/production-server.log file. The -f option continues to print changes to the file as they are added.

      [student@workstation ~]$ tail -f \
      /home/student/AD248/labs/logging-handlers/standalone/log/production-server.log
      01:52:05,392 INFO  [com.redhat.training.view] (default task-1) Test INFO Msg
    4. Send more INFO messages from the application and verify that the messages appear in the log file.

  4. Clean up the server by removing the application.

    1. In the JBoss EAP CLI terminal window, undeploy the application and exit the CLI.

      [standalone@localhost:9990 /] undeploy logtest.war
      no output expected
      [standalone@localhost:9990 /] exit
      no output expected
    2. In the tail command terminal window, stop the command by pressing Ctrl+C.

    3. In the JBoss EAP server terminal window, stop the server by pressing Ctrl+C.

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-handlers

Revision: ad248-7.4-18a9db2