Configuring Logging
Red Hat JBoss EAP 8 Logging Subsystem
-
Logging is vital for application servers like Red Hat JBoss EAP 8.
-
Red Hat JBoss EAP 8’s logging subsystem, consistent with its modular design, is managed by a subsystem and configured in
domain.xmlfor managed domain mode andstandalone.xmlfor standalone servers. -
The subsystem comprises of three key components:
-
Handlers:
-
These dictate where and how server events are logged.
-
JBoss EAP offers various built-in handlers for logging application messages.
-
-
Loggers:
-
Also known as log categories, these organize events into logical groups based on package namespaces within the Java Virtual Machine.
-
They specify which handlers process and log messages.
-
-
Root Logger:
-
Positioned atop the logger hierarchy, the root logger captures all log messages of a specified level not handled by specific log categories.
-
-
Default Log File Locations
-
Standalone Mode:
-
Log files reside in the standalone/log directory within the base directory.
-
This directory contains two key log files:
-
gc.log.0.current: Managed by settings in BASE_DIR/bin/standalone.sh, exclusively logs JVM flags and memory management events from the latest server startup.
-
server.log: Containing server log events, with ongoing additions, this file’s configurations are specified within the logging subsystem section of standalone.xml.
-
-
-
Domain Mode:
-
Logging spans several locations relative to the base directory.
-
domain/log/host-controller.log: Documents host controller startup events, including connection issues, debug messages, and runtime errors.
-
domain/log/process-controller.log: Records process startup and shutdown events on the host, including those of the host controller and individual servers.
-
domain/servers/<server-name>/log/server.log: Houses log events specific to each server on the host.
-
-
Each server on a host possesses its own log directory. For instance, if a host includes a server named dev-server-one, its log file resides in domain/servers/dev-server-one/log/server.log.
-
|
It’s advisable to regularly rotate server.log files, typically on an hourly or daily basis, or when file size thresholds are met. |
Built-in Log Handlers
-
Red Hat JBoss EAP 8 features built-in handlers, including:
-
Console handler: Writes to the console. Configured using the <console-handler> element.
-
File handler: Writes to a file. Configured using the <file-handler> element.
-
Periodic-rotating file handler: Rotates logs based on time intervals. Configured using the <periodic-rotating-file-handler> element.
-
Size-rotating file handler: Rotates logs based on file size. Configured using the <size-rotating-file-handler> element.
-
Asynchronous handler: Writes logs asynchronously to sub-handlers. Configured using the <async-handler> element.
-
Syslog handler: Sends events to a remote syslog server. configured using the <syslog-handler> element.
-
-
Handlers are configured within the logging subsystem section of the server configuration file.
-
For example, the standalone.xml file and most of the profiles in the domain.xml file come preconfigured with a <console-handler> definition.
[standalone@localhost:9990 /] /subsystem=logging/console-handler=CONSOLE:read-resource { "outcome" => "success", "result" => { "autoflush" => true, "enabled" => true, "encoding" => undefined, "filter" => undefined, "filter-spec" => undefined, "formatter" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n", "level" => "DEBUG", "name" => "CONSOLE", "named-formatter" => "COLOR-PATTERN", "target" => "System.out" } }
Lab 1: Change log level using JBoss CLI
Outcome: In this lab, you check the current log level and change it to "DEBUG" using JBoss EAP CLI.
-
Start the standalone Red Hat JBoss EAP 8 server.
[vagrant@server ~]$ cd /opt/EAP-8.0.0/bin/ [vagrant@server bin]$ sudo -u jboss ./standalone.sh
-
Open another terminal and connect to the JBoss EAP CLI.
[vagrant@server bin]$ sudo -u jboss ./jboss-cli.sh -c
-
Confirm the current log level is "INFO" by executing command shown below.
[standalone@localhost:9990 /] /subsystem=logging/root-logger=ROOT:read-resource { "outcome" => "success", "result" => { "filter" => undefined, "filter-spec" => undefined, "handlers" => [ "CONSOLE", "FILE" ], "level" => "INFO" } } -
Change the log level to "DEBUG" using the command shown below.
[standalone@localhost:9990 /] /subsystem=logging/root-logger=ROOT:write-attribute(name="level", value="DEBUG") {"outcome" => "success"} -
Confirm the log level is updated to "DEBUG".
[standalone@localhost:9990 /] /subsystem=logging/root-logger=ROOT:read-resource { "outcome" => "success", "result" => { "filter" => undefined, "filter-spec" => undefined, "handlers" => [ "CONSOLE", "FILE" ], "level" => "DEBUG" } } -
Notice the logs in the first terminal shows "DEBUG" logs:
...output_omitted... 07:34:51,304 DEBUG [org.jboss.as.repository] (ServerService Thread Pool -- 77) Current content hash references are {f9418ea27525e0f3c02ea099405265246b22b55a=[ContentReference{contentIdentifier=/deployment=kitchensink.war, hexHash=f9418ea27525e0f3c02ea099405265246b22b55a}], 555df23b973ed9f76f7c817deec3bab6a13a7ea3=[ContentReference{contentIdentifier=/deployment=temperature-converter.war, hexHash=555df23b973ed9f76f7c817deec3bab6a13a7ea3}]} 07:39:51,306 DEBUG [org.jboss.as.repository] (ServerService Thread Pool -- 77) Current content hash references are {f9418ea27525e0f3c02ea099405265246b22b55a=[ContentReference{contentIdentifier=/deployment=kitchensink.war, hexHash=f9418ea27525e0f3c02ea099405265246b22b55a}], 555df23b973ed9f76f7c817deec3bab6a13a7ea3=[ContentReference{contentIdentifier=/deployment=temperature-converter.war, hexHash=555df23b973ed9f76f7c817deec3bab6a13a7ea3}]} ...output_omitted... -
Stop the standalone server and JBoss CLI by pressing
Ctrl+C.
Lab 2: Configuring Logging Handlers
Outcome: In this lab, you create a size rotating file handler and verify that it’s created successfully.
-
Start the standalone Red Hat JBoss EAP 8 server.
[vagrant@server ~]$ cd /opt/EAP-8.0.0/bin/ [vagrant@server bin]$ sudo -u jboss ./standalone.sh
-
Open another terminal and connect to the JBoss EAP CLI.
[vagrant@server bin]$ sudo -u jboss ./jboss-cli.sh -c
-
Create custom handler named 'CUSTOM_HANDLER' that would capture all of the logs generated by the category com.example.www in a file called /opt/EAP-8.0.0/standalone/log/logtest.log, after the log file reaches 1 MB in size, the logging subsystem should rotates the log file to a new log file with a numbered suffix.
[standalone@localhost:9990 /] /subsystem=logging/size-rotating-file-handler=CUSTOM_HANDLER/:add\ > (file={"path"=>"logtest.log",\ > "relative-to"=>"jboss.server.log.dir"},\ > formatter="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",\ > level=DEBUG,max-backup-index=3,name=CUSTOM_HANDLER,\ > rotate-size=1m) {"outcome" => "success"} [standalone@localhost:9990 /] /subsystem=logging/logger=com.example.www:add\ (category=com.example.www,handlers=["CUSTOM_HANDLER"]) -
Verify that the handler was added successfully.
[standalone@localhost:9990 /] /subsystem=logging/size-rotating-file-handler=CUSTOM_HANDLER:read-resource { "outcome" => "success", "result" => { "append" => true, "autoflush" => true, "enabled" => true, "encoding" => undefined, "file" => { "path" => "logtest.log", "relative-to" => "jboss.server.log.dir" }, "filter" => undefined, "filter-spec" => undefined, "formatter" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n", "level" => "DEBUG", "max-backup-index" => 3, "name" => "CUSTOM_HANDLER", "named-formatter" => undefined, "rotate-on-boot" => false, "rotate-size" => "1m", "suffix" => undefined } } -
Open a new terminal and confirm the respective log file is create.
[vagrant@server ~]$ ls -ld /opt/EAP-8.0.0/standalone/log/logtest.log -rw-r--r--. 1 jboss jboss 0 Apr 30 08:59 /opt/EAP-8.0.0/standalone/log/logtest.log
-
Stop the standalone server and JBoss CLI by pressing
Ctrl+C.