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 |
|
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
In a terminal window, start the standalone JBoss EAP server.
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.
Use a management CLI script file to create a size-rotating-file-handler and deploy the logtest.war file.
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-batchThe 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.
Run the management CLI script.
[student@workstation ~]$cd /opt/jboss-eap-7.4/binno output expected[student@workstation bin]$./jboss-cli.sh -c --file=/home/student\ /AD248/labs/logging-handlers/add_sizerotating_log.cliThe 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.
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 } }
Verify and observe the server handling the log messages generated by the application.
In a web browser, navigate to http://127.0.0.1:8080/logtest/ to access the logtest application.
![]() |
Fill out the form with the following values:
| Field | Value |
|---|---|
| Level |
INFO
|
| Message |
Test INFO Msg
|
Click to send the log message to the handler you created previously.
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 MsgSend more INFO messages from the application and verify that the messages appear in the log file.
Clean up the server by removing the application.
In the JBoss EAP CLI terminal window, undeploy the application and exit the CLI.
[standalone@localhost:9990 /]undeploy logtest.warno output expected
[standalone@localhost:9990 /]exitno output expected
In the tail command terminal window, stop the command by pressing Ctrl+C.
In the JBoss EAP server terminal window, stop the server by pressing Ctrl+C.