Manipulate the logging levels of a size rotating file handler, and deploy an application that uses this handler to log messages.
| Resources | |
|---|---|
| Files: |
|
| 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
Start the standalone JBoss EAP server.
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.
Use the management CLI to configure the log handler and deploy the example application.
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
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"}Deploy the logtest.war application.
[standalone@localhost:9990] deploy \
/home/student/AD248/labs/logging-levels/logtest.warAttach 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"}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.
Navigate to http://127.0.0.1:8080/logtest/ to access the logtest application.
Fill out the form by using the following values:
| Field | Value |
|---|---|
| Level |
INFO
|
| Message |
INFO Log Level Test
|
Click to send the log message to the handler.
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 TestSend more INFO messages from the application and verify that the messages appear in the log file.
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.
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.
Change the log handler level and verify that the handler processes logs at or below its updated log level.
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"}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.
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.
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.
Clean up the classroom environment.
Use the management CLI to undeploy the logtest.war application.
[standalone@localhost:9990 /] undeploy logtest.warExit the management CLI.
[standalone@localhost:9990 /] exitIn its terminal window, stop the tail command by pressing Ctrl+C.
Stop the instance of JBoss EAP by pressing Ctrl+C in the terminal window that is running JBoss EAP.