Chapter 10. Logging with JBoss EAP
JBoss EAP provides highly-configurable logging facilities for both its internal use and for deployed applications. The logging
subsystem is based on JBoss LogManager and supports several third-party application logging frameworks in addition to JBoss Logging.
10.1. Logging mechanisms in JBoss EAP
JBoss EAP provides a range of logging mechanisms to support monitoring, troubleshooting, and managing the server environment. Understanding these mechanisms helps in maintaining and debugging your JBoss EAP setup:
10.1.1. Server logging in JBoss EAP
In JBoss EAP, server logging is primarily managed through the server.log
file, where all log entries are recorded.
The location of this log file depends on your operating mode:
-
Standalone server:
EAP_HOME/standalone/log/server.log
-
Managed domain:
EAP_HOME/domain/servers/SERVER_NAME/log/server.log
This file is commonly known as the server log.
Additional resources
10.1.2. Bootup logging in JBoss EAP
During bootup, JBoss EAP logs information about the Java environment and the startup of each service. This log is useful for troubleshooting and is written to the server log by default.
Bootup logging is configured in the logging.properties
file, which is used until the JBoss EAP logging
subsystem starts.
The file location depends on your operating mode:
-
Standalone server:
EAP_HOME/standalone/configuration/logging.properties
Managed domain: There is a
logging.properties
file for both the domain controller and each server.-
Domain controller:
EAP_HOME/domain/configuration/logging.properties
Server:
EAP_HOME/domain/servers/SERVER_NAME/data/logging.properties
WarningDo not directly edit the
logging.properties
file unless necessary. If you have a specific use case, consult Red Hat Customer Portal before making changes.Manual modifications to the
logging.properties
file are overwritten on startup.
-
Domain controller:
10.1.2.1. Viewing bootup errors
When troubleshooting JBoss EAP, checking for bootup errors is a key step. You can use this information to diagnose and resolve the errors. If needed, open a support case for assistance in troubleshooting bootup errors.
You can view bootup errors in the following ways:
-
Reviewing bootup errors in the
server.log
file - Reading bootup errors with the management CLI command
Each method has its own advantages depending on your requirements.
10.1.2.1.1. Reviewing bootup errors in server.log
file
You can open the server.log
file to view any errors that occurred during bootup.
This method provides error messages along with related information, helping you understand the cause of the errors. It displays error messages in plain text format.
Prerequisites
- You have access to the JBoss EAP server’s file system.
-
You can access the
server.log
file for review.
Procedure
-
Open the
server.log
file in a file viewer. - Navigate to the end of the file.
-
Search backward for the
WFLYSRV0049
message identifier, which indicates the start of the latest bootup sequence. Search the log from that point onward for instances of
ERROR
. Each instance will include a description of the error and list the modules involved.The following is an example error description from the
server.log
log file.Copy to Clipboard Copied! Toggle word wrap Toggle overflow 2016-03-16 14:32:01,627 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.undertow.listener.default: org.jboss.msc.service.StartException in service jboss.undertow.listener.default: Could not start http listener at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:142) at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.net.BindException: Address already in use ...
2016-03-16 14:32:01,627 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.undertow.listener.default: org.jboss.msc.service.StartException in service jboss.undertow.listener.default: Could not start http listener at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:142) at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.net.BindException: Address already in use ...
10.1.2.1.2. Reading bootup errors with the management CLI command
When troubleshooting JBoss EAP, you can use the read-boot-errors
management CLI command to view errors reported during bootup.
This method is useful if you do not have access to the file system of the server, enabling remote monitoring and error checking through scripting. With the management CLI command, you can identify and address boot errors. For example, you can write a script that starts multiple JBoss EAP instances and check for bootup errors.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Launch the management CLI.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow <EAP_HOME>/bin/jboss-cli.sh
$ <EAP_HOME>/bin/jboss-cli.sh
Run the following management CLI command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /core-service=management:read-boot-errors
/core-service=management:read-boot-errors
Review the output to see a list of any errors that occurred during bootup.
- Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow { "outcome" => "success", "result" => [ { "failed-operation" => { "operation" => "add", "address" => [ ("subsystem" => "undertow"), ("server" => "default-server"), ("http-listener" => "default") ] }, "failure-description" => "{\"WFLYCTL0080: Failed services\" => {\"jboss.undertow.listener.default\" => \"org.jboss.msc.service.StartException in service jboss.undertow.listener.default: Could not start http listener Caused by: java.net.BindException: Address already in use\"}}", "failed-services" => {"jboss.undertow.listener.default" => "org.jboss.msc.service.StartException in service jboss.undertow.listener.default: Could not start http listener Caused by: java.net.BindException: Address already in use"} } ... ] }
{ "outcome" => "success", "result" => [ { "failed-operation" => { "operation" => "add", "address" => [ ("subsystem" => "undertow"), ("server" => "default-server"), ("http-listener" => "default") ] }, "failure-description" => "{\"WFLYCTL0080: Failed services\" => {\"jboss.undertow.listener.default\" => \"org.jboss.msc.service.StartException in service jboss.undertow.listener.default: Could not start http listener Caused by: java.net.BindException: Address already in use\"}}", "failed-services" => {"jboss.undertow.listener.default" => "org.jboss.msc.service.StartException in service jboss.undertow.listener.default: Could not start http listener Caused by: java.net.BindException: Address already in use"} } ... ] }
10.1.3. Garbage collection logging in JBoss EAP
Garbage collection logging records all garbage collection activity in plain text log files. These logs are useful for diagnostic purposes.
The garbage collection logs are located at EAP_HOME/standalone/log/gc.log.DIGIT.current
. Each log file is limited to 3 MB, and up to five files are rotated.
It is recommended to keep garbage collection logging enabled, as it helps with troubleshooting and has minimal overhead. However, you can disable it for a standalone server by setting the GC_LOG
variable to false
before starting the server. For example:
export GC_LOG=false EAP_HOME/bin/standalone.sh
$ export GC_LOG=false
$ EAP_HOME/bin/standalone.sh
10.1.4. Default log file locations in JBoss EAP
The following log files are created based on the default logging configurations. These configurations use periodic log handlers to write the server log files.
Log File | Description |
---|---|
| Contains server log messages, including startup messages. |
| Contains garbage collection details. |
Log File | Description |
---|---|
| Contains log messages related to the startup of the host controller. |
| Contains log messages related to the startup of the process controller. |
| Contains log messages for the named server, including startup messages. |
10.1.5. Setting the default locale of the server in JBoss EAP
You can configure the default locale for JBoss EAP by setting JVM properties to the startup configuration file. The startup configuration file is EAP_HOME/bin/standalone.conf
for a standalone server or EAP_HOME/bin/domain.conf
for a managed domain.
For Windows server, the JBoss EAP startup configuration files are standalone.conf.bat
and domain.conf.bat
.
Log messages that have been internationalized and localized will use this default locale.
Prerequisites
- JBoss EAP is running.
- You have access to the startup configuration file for your server mode.
Procedure
Set the language by adding the
user.language
property to theJAVA_OPTS
variable. For example, to set the locale to French, add the following line to the startup configuration file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow JAVA_OPTS="$JAVA_OPTS -Duser.language=fr"
JAVA_OPTS="$JAVA_OPTS -Duser.language=fr"
Set the language and country by adding the
user.language
anduser.country
properties. For example, to set the locale to Brazilian Portuguese, add the following line:Copy to Clipboard Copied! Toggle word wrap Toggle overflow JAVA_OPTS="$JAVA_OPTS -Duser.language=pt -Duser.country=BR"
JAVA_OPTS="$JAVA_OPTS -Duser.language=pt -Duser.country=BR"
Set the server locale using the o`rg.jboss.logging.locale` property to specify a different locale for log messages. This overrides the default locale for logging. For example, to set the server locale to Brazilian Portuguese, add the following line:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.logging.locale=pt-BR"
JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.logging.locale=pt-BR"
This property affects only log messages that use JBoss Logging and its dependencies. Other dependencies, such as Jakarta Server Faces, cannot get an overridden locale.
NoteTo start JBoss EAP with a different locale than the system default, edit
EAP_HOME/bin/standalone.conf
for standalone mode orEAP_HOME/bin/domain.conf
for managed domain mode. Use theorg.jboss.logging.locale
property to set the locale in BCP 47 format.
Additional resources
10.2. Viewing log files
Viewing server and application logs is crucial for diagnosing errors, performance issues, and other problems.
You can view logs using the following methods:
Consider the following key points regarding log access and management:
-
Logs must be located in the directory specified by the server’s
jboss.server.log.dir
property. - Logs are defined as file, periodic rotating, size rotating, or periodic size rotating log handlers.
- Role-Based Access Control (RBAC) limits users to viewing only the logs they are authorized to access in the management console or CLI.
10.2.1. Viewing logs from the management console
You can view logs directly from the JBoss EAP management console, which provides a graphical interface for log access.
Prerequisites
- JBoss EAP is running.
- You have access to the management console.
Procedure
- Log in to the management console.
- Select the Runtime tab and choose the appropriate server.
- Select Log Files and choose a log file from the list.
Click View to open and search the log contents, or choose Download from the dropdown to save the log file to your local file system.
WarningThe management console log viewer is not designed for very large log files, for example, greater than 100MB. You will receive a confirmation prompt if you attempt to open a log file larger than 15MB. Opening a very large file in the management console may crash your browser. It is recommended to download large log files and open them in a text editor.
10.2.2. Viewing logs from the management CLI
You can read log file contents from the management CLI using the read-log-file
command. By default, this displays the last 10
lines of the specified log file.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Use the following command to read the contents of a log file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/log-file=LOG_FILE_NAME:read-log-file
/subsystem=logging/log-file=LOG_FILE_NAME:read-log-file
NoteIn a managed domain, precede this command with
/host=HOST_NAME/server=SERVER_NAME
.Customize the log output using the following parameters:
- encoding: Specify the character encoding used to read the file.
-
lines: Set the number of lines to read from the file. A value of
-1
will read all log lines. The default is10
. -
skip: Specify the number of lines to skip before reading. The default is
0
. -
tail: Set whether to read from the end of the file. Defaults to
true
.
For example, the following management CLI command reads the first 5
lines from the top of the server.log
log file.
/subsystem=logging/log-file=server.log:read-log-file(lines=5,tail=false)
/subsystem=logging/log-file=server.log:read-log-file(lines=5,tail=false)
This produces the following output:
{ "outcome" => "success", "result" => [ "2016-03-24 08:49:26,612 INFO [org.jboss.modules] (main) JBoss Modules version 1.5.1.Final-redhat-1", "2016-03-24 08:49:26,788 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final-redhat-1", "2016-03-24 08:49:26,863 INFO [org.jboss.as] (MSC service thread 1-7) WFLYSRV0049: JBoss EAP 7.0.0.GA (WildFly Core 2.0.13.Final-redhat-1) starting", "2016-03-24 08:49:27,973 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)", "2016-03-24 08:49:27,994 INFO [org.xnio] (MSC service thread 1-1) XNIO version 3.3.4.Final-redhat-1" ] }
{
"outcome" => "success",
"result" => [
"2016-03-24 08:49:26,612 INFO [org.jboss.modules] (main) JBoss Modules version 1.5.1.Final-redhat-1",
"2016-03-24 08:49:26,788 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final-redhat-1",
"2016-03-24 08:49:26,863 INFO [org.jboss.as] (MSC service thread 1-7) WFLYSRV0049: JBoss EAP 7.0.0.GA (WildFly Core 2.0.13.Final-redhat-1) starting",
"2016-03-24 08:49:27,973 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)",
"2016-03-24 08:49:27,994 INFO [org.xnio] (MSC service thread 1-1) XNIO version 3.3.4.Final-redhat-1"
]
}
10.3. Overview of logging subsystem configuration
The JBoss EAP logging
subsystem uses log categories and log handlers for configuration. Log categories specify which messages to capture, while log handlers define how to handle those messages, such as writing them to disk or sending them to the console.
Application logging profiles let you create uniquely-named logging configurations that can be assigned to a deployment or multiple deployments, separate from the main logging settings. Logging profile configuration is nearly identical to that of the main logging
subsystem.
10.3.1. Root logger configuration
The JBoss EAP root logger captures all log messages at the specified log level or higher that are not captured by a logger. However, if a defined logger has use-parent-handlers
set to true and also has a handler defined, both the defined logger and the root logger will be used to process the message.
By default, the root logger uses a console and a periodic log handler, which writes to the server.log
file. This file is commonly known as the server log.
Additional resources
10.3.2. Log categories in JBoss EAP
A log category defines a set of log messages to capture and one or more log handlers that will process those messages.
The log messages are determined by the specified origin and log level. Any string value may be specified. However, package names or class names are preferred. The logger name is specified using dot notation, for example, Logger.getLogger("example.logger.name")
. The log manager processes each section of the name and checks for a matching configuration. If found and use-parent-handlers
is set to false, the process stops. If the configuration is not defined or use-parent-handlers
is set to true, by default, the log manager continues checking parent names, such as "example.logger". The logger configuration depends on how the logger is created, not the package or class name.
Although the log category is typically based on the Java package and class name, it can be any name specified by the Logger.getLogger(LOGGER_NAME)
method.
A logger can have a handler assigned. If the use-parent-handlers
is set to false
, no higher-level loggers will process the message, even if the logger determines it is loggable. For example, if the logger name is org.jboss.as.logging
and it is configured with use-parent-handlers=false
, the org.jboss.as
logger will not be checked.
Additional resources
10.3.3. Log handlers in JBoss EAP
Log handlers define how captured log messages are recorded, specifying the destination and format for entries. Understanding the different types of log handlers is essential for effective logging configuration, as each type serves distinct purposes tailored to various needs.
A log handler must be added to at least one logger to be active.
Additional resources
- Types of Log Handlers
10.3.3.1. Types of log handlers
Log handlers classify into several types that determine how log entries are processed and stored. Each type has distinct features to meet various logging requirements:
-
Console: Writes log messages to either the host operating system’s standard out,
stdout
, or standard error,stderr
, stream. These messages are displayed when JBoss EAP runs from a command line prompt. The messages from a console log handler are not saved unless the operating system is configured to capture the standard out or standard error stream. - File: Writes log messages to a specified file.
- Periodic: Writes log messages to a named file until a specified time period elapses. After that, the file is renamed with a timestamp, and the handler continues writing to a new created log file with the original name.
- Size: Writes log messages to a named file until the file reaches a specified size. When the file reaches that size, it is renamed with a numeric suffix, and the handler continues to write into a newly created log file with the original name. Each size log handler must specify the maximum number of files to keep in this manner.
- Periodic Size: Writes log messages to a named file until the file reaches the specified size or the specified time period expires. The handler then renames the file and continues writing to a newly created log file with the original name. This handler combines the features of both periodic and size log handlers.
- Syslog: Sends messages to a remote logging server. This enables multiple applications to send their log messages to the same server for parsing.
- Socket: Sends log messages over a socket to a remote logging server. This can use either a TCP or UDP socket.
-
Custom: Enables you to configure new types of log handlers. A custom handler must be implemented as a Java class that extends
java.util.logging.Handler
and included in a module. You can also use a Log4J appender as a custom log handler. - Async: Provides asynchronous behavior for one or more other log handlers. This is useful for log handlers that might have high latency or performance issues, such as writing log files to a network file system.
Additional resources
10.3.4. Supported log levels in JBoss EAP
A log level is an enumerated value that indicates the nature and severity of a log message. As a developer, you can specify the level of a log message using the appropriate method of your chosen logging framework to send the message.
JBoss EAP supports all log levels used by the supported application logging frameworks. The most commonly used log levels from lowest to highest are TRACE
, DEBUG
, INFO
, WARN
, ERROR
, and FATAL
.
Log levels help log categories and handlers limit the messages they process. Each log level has an assigned numeric value indicating its order relative to other log levels. Log categories and handlers are assigned a log level and process only log messages of that level or higher. For example, a log handler with the level of WARN
records messages at the WARN
, ERROR
, and FATAL
.
Log Level | Value | Description |
---|---|---|
ALL | Integer.MIN_VALUE | Provides all log messages. |
FINEST | 300 | - |
FINER | 400 | - |
TRACE | 400 |
|
DEBUG | 500 |
|
FINE | 500 | - |
CONFIG | 700 | - |
INFO | 800 |
|
WARN | 900 |
|
WARNING | 900 | - |
ERROR | 1000 |
|
SEVERE | 1000 | - |
FATAL | 1100 |
|
OFF | Integer.MAX_VALUE | Does not display any log message. |
ALL
is the lowest log level and includes messages of all log levels. This provides the most amount of logging.
FATAL
is the highest log level and includes only messages of that level. This provides the least amount of logging.
10.3.5. Log formatters in JBoss EAP
Log formatters are used to format a log message. You can assign a formatter to a logging handler using the named-formatter
attribute.
Additional resources
10.3.5.1. Types of log formatters
Log formatters classify into several types that determine how log entries are formatted.
The logging subsystem includes four types of formatters:
-
Pattern formatter: Formats log messages in plain text. In addition to using the formatter as the
named-formatter
attribute of log handlers, you can also use it as aformatter
attribute without the need to create the formatter resource first. - JSON formatter: Formats log messages in JSON.
- XML formatter: Formats log messages in XML.
-
Custom formatter: Used with handlers. Most log records are formatted in the printf format. Formatters may require invocation of the
org.jboss.logmanager.ExtLogRecord#getFormattedMessage()
for proper formatting.
10.3.6. Filter expressions for logging in JBoss EAP
Filter expressions, configured using the filter-spec
attribute, record log messages based on various criteria. Filters are applied to raw, unformatted messages. You can add a filter to a logger or handler, but the logger filter takes precedence over the filter put on a handler.
A filter-spec
specified for the root logger is not inherited by other loggers. Instead a filter-spec
must be specified per handler.
The following table describes the available filter expressions for logging:
Filter Expression | Description |
---|---|
accept | Accepts all log messages. |
deny | Denies all log messages. |
not[filter expression] | Returns the inverted value of a single filter expression. For example:
|
all[filter expression] | Returns the concatenated value from a comma-separated list of filter expressions. For example:
|
any[filter expression] | Returns one value from a comma-separated list of filter expressions. For example:
|
levelChange[level] | Updates the log record with the specified level. For example:
|
levels[levels] | Filters log messages with a level listed in the comma-separated list of levels. For example:
|
levelRange[minLevel,maxLevel] |
Filters log messages within the specified level range. The
|
match["pattern"] | Filters log messages using the provided regular expression. For example:
|
substitute["pattern","replacement value"] | Replaces the first match to the pattern (first argument) with the replacement text (second argument). For example:
|
substituteAll["pattern","replacement value"] | Replaces all matches of the pattern (first argument) with the replacement text (second argument). For example:
|
When configuring the filter expression using the management CLI, escape commas and quotation marks in the filter text to ensure the value is correctly processed as a string. You must precede commas and quotation marks with a backslash (\
) and wrap the entire expression in quotation marks. Below is an example that properly escapes substituteAll("WFLY","YLFW")
.
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=filter-spec, value="substituteAll(\"WFLY\"\,\"YLFW\")")
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=filter-spec, value="substituteAll(\"WFLY\"\,\"YLFW\")")
10.3.7. Implicit logging dependencies in JBoss EAP
By default, the JBoss EAP logging
subsystem adds implicit logging API dependencies to deployments. You can manage whether these implicit dependencies are added to deployments by using the add-logging-api-dependencies
attribute, which is set to true
by default.
To prevent these dependencies from being added, set the add-logging-api-dependencies
attribute to false
using the management CLI:
/subsystem=logging:write-attribute(name=add-logging-api-dependencies, value=false)
/subsystem=logging:write-attribute(name=add-logging-api-dependencies, value=false)
Additional resources
10.4. Configuring log categories
You can configure log categories in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Categories.
You can perform the following tasks to configure a log category:
If you configure this log category for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
10.4.1. Adding and configuring a log category using the management CLI
The log category name is typically the Java package of origin. However, a logger can use any string name based on your requirements. For more information, see the Java logging API documentation. Messages from classes in that package are captured if they meet other settings, such as the log level.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add a log category by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logger=LOG_CATEGORY:add
/subsystem=logging/logger=LOG_CATEGORY:add
You can set one or more of the following log category attributes based on your needs:
Set the log level for the log category by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logger=LOG_CATEGORY:write-attribute(name=level,value=LEVEL)
/subsystem=logging/logger=LOG_CATEGORY:write-attribute(name=level,value=LEVEL)
The default is
ALL
.Set whether this category should use the log handlers of the root logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logger=LOG_CATEGORY:write-attribute(name=use-parent-handlers,value=USE_PARENT_HANDLERS)
/subsystem=logging/logger=LOG_CATEGORY:write-attribute(name=use-parent-handlers,value=USE_PARENT_HANDLERS)
By default, log categories use the handlers of the root logger in addition to their own. Set the
use-parent-handlers
attribute tofalse
to ensure the log category uses only its assigned handlers.Set the filter expression by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logger=LOG_CATEGORY:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
/subsystem=logging/logger=LOG_CATEGORY:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
Specify the expression to filter log messages for the log category. Escape any commas and quotation marks, and surround the expression with quotation marks. For example, replace the
FILTER_EXPRESSION
variable with"not(match(\"WFLY\"))"
to set a filter expression ofnot(match("WFLY"))
.
10.4.2. Assigning log handlers and managing log categories
Log handlers in JBoss EAP control how log messages are processed and recorded for log categories. Assign a log handler to a specific log category to customize logging behavior to your application’s needs. You can also remove a log category when it is no longer needed, keeping your logging configuration organized and efficient.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Assign a log handler to the log category by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logger=LOG_CATEGORY:add-handler(name=LOG_HANDLER_NAME)
/subsystem=logging/logger=LOG_CATEGORY:add-handler(name=LOG_HANDLER_NAME)
If needed, you can remove a log category by using the
remove
operation with the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logger=LOG_CATEGORY:remove
/subsystem=logging/logger=LOG_CATEGORY:remove
NoteYou can remove a log category when it is no longer required for your logging configuration.
10.5. Configuring log handlers
Log handlers define how captured log messages are recorded.
See the appropriate section to configure the specific log handler:
- Configuring a console log handler
- Configuring a file log handler
- Configuring a periodic rotating log handler
- Configuring a size rotating log handler
- Configuring a periodic size rotating log handler
- Configuring a syslog handler
- Configuring a socket log handler
- Configuring a custom log handler
- Configuring an async log handler
10.5.1. Configuring a console log handler
You can configure a console log handler in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Handler > Console Handler.
You can perform the following tasks to configure a console log handler:
- Add a new console log handler
- Configure the console log handler settings
- Assign the console log handler to a logger
If you configure this log handler for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add a console log handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:add
/subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:add
You can set one or more of the following console log handler attributes based on your needs:
Set the log level for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
/subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
The default is
ALL
.Set the target for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=target,value=TARGET)
/subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=target,value=TARGET)
The target can be
System.out
,System.err
, orconsole
. The default isSystem.out
.Set the encoding for the handler, such as
utf-8
, by using the following command.Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
/subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
Set the formatter string for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
/subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
For example, the default format string is
%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n
. Enclose theFORMAT
value in quotation marks.NoteUse the
named-formatter
attribute if you want to reference a saved formatter.Set auto flush by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
/subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
Specify whether to automatically flush after each write. The default value is
true
.Set the filter expression by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
/subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
Specify the expression to filter log messages for the handler. Escape any commas and quotation marks, and surround the expression with quotation marks. For example, replace the
FILTER_EXPRESSION
variable with"not(match(\"WFLY\"))"
to create a filter expression ofnot(match("WFLY"))
.
Assign the console log handler to a logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=CONSOLE_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:add-handler(name=CONSOLE_HANDLER_NAME)
To activate the log handler, you can assign the console log handler to the root logger or any other logger.
If needed, you can remove a log handler by using the
remove
operation with the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:remove
/subsystem=logging/console-handler=CONSOLE_HANDLER_NAME:remove
NoteYou can remove a log handler when it is no longer required for your logging configuration. However, a log handler cannot be removed if it is currently assigned to a logger or an async log handler.
Next steps
Additional resources
10.5.2. Configuring a file log handler
You can configure a file log handler in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Handler > File Handler.
You can perform the following tasks to configure a file log handler:
- Add a new file log handler
- Configure the file log handler settings
- Assign the file log handler to a logger
If you configure this log handler for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add a file log handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/file-handler=FILE_HANDLER_NAME:add(file={path=FILE_PATH,relative-to=RELATIVE_TO_PATH})
/subsystem=logging/file-handler=FILE_HANDLER_NAME:add(file={path=FILE_PATH,relative-to=RELATIVE_TO_PATH})
NoteWhen you add a file log handler, specify the file path using the
file
attribute, which consists of thepath
andrelative-to
attributes. Use thepath
attribute to set the log file path, including the file name, for example,my-log.log
. Optionally, use therelative-to
attribute to indicate that the path is relative to a named path, such asjboss.server.log.dir
.You can set one or more of the following file log handler attributes based on your needs:
Set the log level for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
/subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
The default is
ALL
.Set the append behavior for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=append,value=APPEND)
/subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=append,value=APPEND)
Set the
append
attribute tofalse
to overwrite the file upon server restart. By default, JBoss EAP appends log messages to the same file when the server restarts.Set the encoding for the handler, such as
utf-8
, by using the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
/subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
Set the formatter string for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
/subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
For example, the default format string is
%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n
. Enclose theFORMAT
value in quotation marks.NoteUse the
named-formatter
attribute if you want to reference a saved formatter.Set auto flush by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
/subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
Specify whether to automatically flush after each write. The default value is
true
.Set the filter expression by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
/subsystem=logging/file-handler=FILE_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
Specify the expression to filter log messages for the handler. Escape any commas and quotation marks, and surround the expression with quotation marks. For example, replace the
FILTER_EXPRESSION
variable with"not(match(\"WFLY\"))"
to create a filter expression ofnot(match("WFLY"))
.
Assign the file log handler to a logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=FILE_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:add-handler(name=FILE_HANDLER_NAME)
To activate the log handler, you can assign the file log handler to the root logger or any other logger.
Assign the file log handler to a specific logger named
CATEGORY
by using the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logger=CATEGORY:add-handler(name=FILE_HANDLER_NAME)
/subsystem=logging/logger=CATEGORY:add-handler(name=FILE_HANDLER_NAME)
Replace
CATEGORY
with the name of the logger to which you want to assign the file log handler.If needed, you can remove a log handler by using the
remove
operation with the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/file-handler=FILE_HANDLER_NAME:remove
/subsystem=logging/file-handler=FILE_HANDLER_NAME:remove
NoteYou can remove a log handler when it is no longer required for your logging configuration. However, a log handler cannot be removed if it is currently assigned to a logger or an async log handler.
Next steps
Additional resources
10.5.3. Configuring a periodic rotating log handler
You can configure a periodic rotating log handler in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Handler > Periodic Handler.
You can perform the following tasks to configure a periodic rotating log handler:
- Add a new periodic rotating log handler
- Configure the periodic rotating log handler settings
- Assign the periodic rotating log handler to a logger
If you configure this log handler for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add a periodic rotating log handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:add(file={path=FILE_PATH,relative-to=RELATIVE_TO_PATH},suffix=SUFFIX)
/subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:add(file={path=FILE_PATH,relative-to=RELATIVE_TO_PATH},suffix=SUFFIX)
NoteWhen you add a periodic rotating log handler, specify the file path using the
file
attribute, which consists of thepath
andrelative-to
attributes. Use thepath
attribute to set the log file path, including the file name, for example,my-log.log
. Optionally, use therelative-to
attribute to indicate that the path is relative to a named path, such asjboss.server.log.dir
.You must set the suffix for rotated logs by using the
suffix
attribute. The suffix must follow a format thatjava.text.SimpleDateFormat
can understand, such as.yyyy-MM-dd-HH
. The rotation period is automatically calculated based on this suffix.You can set one or more of the following periodic rotating log handler attributes based on your needs:
Set the log level for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
/subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
The default is
ALL
.Set the append behavior for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=append,value=APPEND)
/subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=append,value=APPEND)
Set the
append
attribute tofalse
to overwrite the file upon server restart. By default, JBoss EAP appends log messages to the same file when the server restarts.Set the encoding for the handler, such as
utf-8
, by using the following command.Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
/subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
Set the formatter string for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
/subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
For example, the default format string is
%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n
. Enclose theFORMAT
value in quotation marks.NoteUse the
named-formatter
attribute if you want to reference a saved formatter.Set auto flush by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
/subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
Specify whether to automatically flush after each write. The default value is
true
.Set the filter expression by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
/subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
Specify the expression to filter log messages for the handler. Escape any commas and quotation marks, and surround the expression with quotation marks. For example, replace the
FILTER_EXPRESSION
variable with"not(match(\"WFLY\"))"
to create a filter expression ofnot(match("WFLY"))
.
Assign the periodic rotating log handler to a logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=PERIODIC_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:add-handler(name=PERIODIC_HANDLER_NAME)
To activate the log handler, you can assign the periodic rotating log handler to the root logger or any other logger.
If needed, you can remove a log handler by using the
remove
operation with the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:remove
/subsystem=logging/periodic-rotating-file-handler=PERIODIC_HANDLER_NAME:remove
NoteYou can remove a log handler when it is no longer required for your logging configuration. However, a log handler cannot be removed if it is currently assigned to a logger or an async log handler.
Next steps
Additional resources
10.5.4. Configuring a size rotating log handler
You can configure a size log handler in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Handler > Size Handler.
You can perform the following tasks to configure a size log handler:
- Add a new size log handler
- Configure the size log handler settings
- Assign the size log handler to a logger
If you configure this log handler for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add a size log handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:add(file={path=FILE_PATH,relative-to=RELATIVE_TO_PATH})
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:add(file={path=FILE_PATH,relative-to=RELATIVE_TO_PATH})
NoteWhen you add a size log handler, specify the file path using the
file
attribute, which consists of thepath
andrelative-to
attributes. Use thepath
attribute to set the log file path, including the file name, for example,my-log.log
. Optionally, use therelative-to
attribute to indicate that the path is relative to a named path, such asjboss.server.log.dir
.You can set one or more of the following size log handler attributes based on your needs:
Set the log level for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
The default is
ALL
.Set the suffix for rotated logs by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=suffix, value=SUFFIX)
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=suffix, value=SUFFIX)
NoteIf specified, the suffix must follow a format that
java.text.SimpleDateFormat
can understand, such as.yyyy-MM-dd-HH
. The suffix is optional for thesize-rotating-file-handler
. It indicates when the file was rotated, not the rotation period itself.Set the encoding for the handler, such as
utf-8
, by using the following command.Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
/subsystem=logging/size-rotating-file-handler=PERIODIC_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
Set the rotation size by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=rotate-size, value=ROTATE_SIZE)
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=rotate-size, value=ROTATE_SIZE)
Set the maximum file size before rotation. The default is
2m
for 2 megabytes.Set the maximum number of backup logs to keep by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=max-backup-index, value=MAX_BACKUPS)
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=max-backup-index, value=MAX_BACKUPS)
Specify the number of backups to retain. The default is
1
.NoteRotation occurs based on the size limit, not the suffix. If a suffix is defined, it is added to the rotated files, but those files will not be deleted. Only files that reach the size limit are deleted during rotation.
Set whether to rotate the log on boot by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=rotate-on-boot, value=ROTATE_ON_BOOT)
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=rotate-on-boot, value=ROTATE_ON_BOOT)
By default, a new log file is not created on server restart. Set this to
true
to rotate the log when the server restart.Set the append behavior for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=append,value=APPEND)
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=append,value=APPEND)
Set the
append
attribute tofalse
to overwrite the file upon server restart. By default, JBoss EAP appends log messages to the same file when the server restarts.Set the encoding for the handler, such as
utf-8
, by using the following command.Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
Set the formatter string for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
For example, the default format string is
%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n
. Enclose theFORMAT
value in quotation marks.NoteUse the
named-formatter
attribute if you want to reference a saved formatter.Set auto flush by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
Specify whether to automatically flush after each write. The default value is
true
.Set the filter expression by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
Specify the expression to filter log messages for the handler. Escape any commas and quotation marks, and surround the expression with quotation marks. For example, replace the
FILTER_EXPRESSION
variable with"not(match(\"WFLY\"))"
to create a filter expression ofnot(match("WFLY"))
.
Assign the size log handler to a logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=SIZE_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:add-handler(name=SIZE_HANDLER_NAME)
To activate the log handler, you can assign the size log handler to the root logger or any other logger.
If needed, you can remove a log handler by using the
remove
operation with the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:remove
/subsystem=logging/size-rotating-file-handler=SIZE_HANDLER_NAME:remove
NoteYou can remove a log handler when it is no longer required for your logging configuration. However, a log handler cannot be removed if it is currently assigned to a logger or an async log handler.
Additional resources
10.5.5. Configuring a periodic size rotating log handler
You can configure a periodic size rotating log handler in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Handler > Periodic Size Handler.
You can perform the following tasks to configure a periodic size log handler:
- Add a new periodic size log handler
- Configure the periodic size log handler settings
- Assign the periodic size log handler to a logger
If you configure this log handler for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add a periodic size log handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:add(file={path=FILE_PATH,relative-to=RELATIVE_TO_PATH},suffix=SUFFIX)
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:add(file={path=FILE_PATH,relative-to=RELATIVE_TO_PATH},suffix=SUFFIX)
NoteWhen you add a periodic size log handler, specify the file path using the
file
attribute, which consists of thepath
andrelative-to
attributes. Use thepath
attribute to set the log file path, including the file name, for example,my-log.log
. Optionally, use therelative-to
attribute to indicate that the path is relative to a named path, such asjboss.server.log.dir
.You must set the suffix for rotated logs by using the
suffix
attribute. The suffix must follow a format thatjava.text.SimpleDateFormat
can understand, such as.yyyy-MM-dd-HH
. The rotation period is automatically calculated based on this suffix.You can set one or more of the following periodic size log handler attributes based on your needs:
Set the log level for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
The default is
ALL
.Set the rotation size by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=rotate-size, value=ROTATE_SIZE)
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=rotate-size, value=ROTATE_SIZE)
Set the maximum file size before rotation. The default is
2m
for 2 megabytes.Set the maximum number of backup logs to keep by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=max-backup-index, value=MAX_BACKUPS)
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=max-backup-index, value=MAX_BACKUPS)
Specify the number of backups to retain. The default is
1
.NoteWhen rotated by the suffix, the rotated files will not be deleted. Only files that reach the size limit when rotated will be deleted during rotation.
Set whether to rotate the log on boot by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=rotate-on-boot, value=ROTATE_ON_BOOT)
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=rotate-on-boot, value=ROTATE_ON_BOOT)
By default, a new log file is not created on server restart. Set this to
true
to rotate the log when the server restart.Set the append behavior for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=append,value=APPEND)
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=append,value=APPEND)
Set the
append
attribute tofalse
to overwrite the file upon server restart. By default, JBoss EAP appends log messages to the same file when the server restarts.Set the encoding for the handler, such as
utf-8
, by using the following command.Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
Set the formatter string for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
For example, the default format string is
%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n
. Enclose theFORMAT
value in quotation marks.NoteUse the
named-formatter
attribute if you want to reference a saved formatter.Set auto flush by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
Specify whether to automatically flush after each write. The default value is
true
.Set the filter expression by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
Specify the expression to filter log messages for the handler. Escape any commas and quotation marks, and surround the expression with quotation marks. For example, replace the
FILTER_EXPRESSION
variable with"not(match(\"WFLY\"))"
to create a filter expression ofnot(match("WFLY"))
.
Assign the periodic size log handler to a logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=PERIODIC_SIZE_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:add-handler(name=PERIODIC_SIZE_HANDLER_NAME)
To activate the log handler, you can assign the periodic size log handler to the root logger or any other logger.
If needed, you can remove a log handler by using the
remove
operation with the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:remove
/subsystem=logging/periodic-size-rotating-file-handler=PERIODIC_SIZE_HANDLER_NAME:remove
NoteYou can remove a log handler when it is no longer required for your logging configuration. However, a log handler cannot be removed if it is currently assigned to a logger or an async log handler.
Next steps
Additional resources
10.5.6. Configuring a syslog handler
You can configure a syslog handler in JBoss EAP by using the management CLI. This handler sends messages to a remote logging server that supports the Syslog protocol, either RFC-3164 or RFC-5424. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Handler > Syslog Handler.
You can perform the following tasks to configure a syslog handler:
- Add a new syslog handler
- Configure the syslog handler settings
- Assign the syslog handler to a logger
If you configure this log handler for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add a syslog handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:add
/subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:add
You can set one or more of the following syslog handler attributes based on your needs:
Set the log level for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
/subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
The default is
ALL
.Set the application name for logging by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=app-name,value=APP_NAME)
/subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=app-name,value=APP_NAME)
The default application name is
java
.Set the address of the syslog server by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=server-address,value=SERVER_ADDRESS)
/subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=server-address,value=SERVER_ADDRESS)
The default address is
localhost
.Set the port of the syslog server by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=port,value=PORT)
/subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=port,value=PORT)
The default port is
514
.Set the syslog format according to an RFC specification by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=syslog-format,value=SYSLOG_FORMAT)
/subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=syslog-format,value=SYSLOG_FORMAT)
The default format is
RFC5424
.Specify the
named-formatter
attribute to format the syslog payload message by using the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=named-formatter, value=FORMATTER_NAME)
/subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:write-attribute(name=named-formatter, value=FORMATTER_NAME)
Assign the syslog handler to a logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=SYSLOG_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:add-handler(name=SYSLOG_HANDLER_NAME)
To activate the log handler, you can assign the syslog handler to the root logger or any other logger.
If needed, you can remove a log handler by using the
remove
operation with the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:remove
/subsystem=logging/syslog-handler=SYSLOG_HANDLER_NAME:remove
NoteYou can remove a log handler when it is no longer required for your logging configuration. However, a log handler cannot be removed if it is currently assigned to a logger or an async log handler.
Next steps
Additional resources
10.5.7. Configuring a socket log handler
You can configure a socket log handler in JBoss EAP by using the management CLI. The handler sends messages over a TCP or UDP socket. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Handler > Socket Handler.
If the server starts in admin-only mode, it discards log messages.
You can perform the following tasks to configure a socket log handler:
- Add a socket binding
- Add a log formatter
- Add the socket log handler
- Configure the settings
- Assign the socket log handler to a logger
If you configure this log handler for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add the socket binding by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /socket-binding-group=SOCKET_BINDING_GROUP/remote-destination-outbound-socket-binding=SOCKET_BINDING_NAME:add(host=HOST, port=PORT)
/socket-binding-group=SOCKET_BINDING_GROUP/remote-destination-outbound-socket-binding=SOCKET_BINDING_NAME:add(host=HOST, port=PORT)
NoteYou can define either a
remote-destination-outbound-socket-binding
orlocal-destination-outbound-socket-binding
as the socket binding to use.Add the log formatter to use, such as a JSON formatter, by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/json-formatter=FORMATTER:add
/subsystem=logging/json-formatter=FORMATTER:add
Add the socket log handler by specifying the socket binding and formatter to use by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:add(outbound-socket-binding-ref=SOCKET_BINDING_NAME,named-formatter=FORMATTER)
/subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:add(outbound-socket-binding-ref=SOCKET_BINDING_NAME,named-formatter=FORMATTER)
You can set one or more of the following socket log handler attributes based on your needs:
Set the protocol by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:write-attribute(name=protocol,value=PROTOCOL)
/subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:write-attribute(name=protocol,value=PROTOCOL)
The default protocol is
TCP
.Set the log level for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
/subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
The default is
ALL
.NoteDuring server startup, log messages handled by a socket log handler are queued until the socket binding is configured and the
logging
subsystem is initialized. If the log level is set low, such asTRACE
orDEBUG
, it can result in large memory consumption during startup.Set the encoding for the handler, such as
utf-8
, by using the following command.Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
/subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
Set auto flush by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
/subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:write-attribute(name=autoflush,value=AUTO_FLUSH)
Specify whether to automatically flush after each write. The default value is
true
.Set the filter expression by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
/subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
Specify the expression to filter log messages for the handler. Escape any commas and quotation marks, and surround the expression with quotation marks. For example, replace the
FILTER_EXPRESSION
variable with"not(match(\"WFLY\"))"
to create a filter expression ofnot(match("WFLY"))
.
Assign the socket log handler to a logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=SOCKET_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:add-handler(name=SOCKET_HANDLER_NAME)
To activate the log handler, you can assign the socket log handler to the root logger or any other logger.
If needed, you can remove a socket log handler by using the
remove
operation with the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:remove
/subsystem=logging/socket-handler=SOCKET_HANDLER_NAME:remove
NoteYou can remove a log handler when it is no longer required for your logging configuration. However, a log handler cannot be removed if it is currently assigned to a logger or an async log handler.
Next steps
Additional resources
10.5.7.1. Sending socket log messages over SSL/TLS
You can set up a socket log handler to send log messages over a socket by using the SSL_TCP
protocol. This setup involves configuring key components in the elytron
subsystem, including a keystore, trust manager, and client SSL context. This configuration ensures secure transmission of log messages from the root logger over the specified socket, with the messages formatted by a JSON formatter.
Prerequisites
- JBoss EAP is running.
Procedure
Configure the Elytron settings by following these steps:
Add the keystore by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=elytron/key-store=log-server-ks:add(path=/path/to/keystore.jks, type=JKS, credential-reference={clear-text=mypassword})
/subsystem=elytron/key-store=log-server-ks:add(path=/path/to/keystore.jks, type=JKS, credential-reference={clear-text=mypassword})
Add the trust manager by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=elytron/trust-manager=log-server-tm:add(key-store=log-server-ks)
/subsystem=elytron/trust-manager=log-server-tm:add(key-store=log-server-ks)
Add the client SSL context by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=elytron/client-ssl-context=log-server-context:add(trust-manager=log-server-tm, protocols=["TLSv1.2"])
/subsystem=elytron/client-ssl-context=log-server-context:add(trust-manager=log-server-tm, protocols=["TLSv1.2"])
Add the socket binding by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=log-server:add(host=localhost, port=4560)
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=log-server:add(host=localhost, port=4560)
Add a JSON formatter by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/json-formatter=json:add
/subsystem=logging/json-formatter=json:add
Add the socket log handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/socket-handler=log-server-handler:add(named-formatter=json, level=INFO, outbound-socket-binding-ref=log-server, protocol=SSL_TCP, ssl-context=log-server-context)
/subsystem=logging/socket-handler=log-server-handler:add(named-formatter=json, level=INFO, outbound-socket-binding-ref=log-server, protocol=SSL_TCP, ssl-context=log-server-context)
Assign the log handler to the root logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=log-server-handler)
/subsystem=logging/root-logger=ROOT:add-handler(name=log-server-handler)
Additional resources
10.5.8. Configuring a custom log handler
You can configure a custom log handler in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Handler > Custom Handler.
You can perform the following tasks to configure a custom log handler:
- Add a new custom log handler
- Configure the custom log handler settings
- Assign the custom log handler to a logger
If you configure this log handler for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add a custom log handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:add(class=CLASS_NAME,module=MODULE_NAME)
/subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:add(class=CLASS_NAME,module=MODULE_NAME)
NoteWhen you add a custom log handler, specify the Java class of the handler and the JBoss EAP module that contains it. The class must extend
java.util.logging.Handler
.Ensure you have created a module containing the custom logger or this command will fail.
You can set one or more of the following custom log handler attributes based on your needs:
Set the log level for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
/subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
The default is
ALL
.Set the properties for the log handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:write-attribute(name=properties.PROPERTY_NAME,value=PROPERTY_VALUE)
/subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:write-attribute(name=properties.PROPERTY_NAME,value=PROPERTY_VALUE)
The properties must be accessible using a setter method.
Set the encoding for the handler, such as
utf-8
, by using the following command.Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
/subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:write-attribute(name=encoding,value=ENCODING)
Set the formatter string for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
/subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:write-attribute(name=formatter,value=FORMAT)
For example, the default format string is
%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n
. Enclose theFORMAT
value in quotation marks.NoteUse the
named-formatter
attribute if you want to reference a saved formatter.Set the filter expression by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
/subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
Specify the expression to filter log messages for the handler. Escape any commas and quotation marks, and surround the expression with quotation marks. For example, replace the
FILTER_EXPRESSION
variable with"not(match(\"WFLY\"))"
to create a filter expression ofnot(match("WFLY"))
.
Assign the custom log handler to a logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=CUSTOM_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:add-handler(name=CUSTOM_HANDLER_NAME)
To activate the log handler, you can assign the handler to the root logger or any other logger.
Assign the custom log handler to a specific logger named
CATEGORY
by using the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logger=CATEGORY:add-handler(name=CUSTOM_HANDLER_NAME)
/subsystem=logging/logger=CATEGORY:add-handler(name=CUSTOM_HANDLER_NAME)
Replace
CATEGORY
with the name of the logger to which you want to assign the custom log handler.If needed, you can remove a custom log handler by using the
remove
operation with the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:remove
/subsystem=logging/custom-handler=CUSTOM_HANDLER_NAME:remove
NoteYou can remove a log handler when it is no longer required for your logging configuration. However, a log handler cannot be removed if it is currently assigned to a logger or an async log handler.
Next steps
Additional resources
10.5.9. Configuring an async log handler
You can configure an async log handler in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Handler > Async Handler.
You can perform the following tasks to configure an async log handler:
- Add a new async log handler
- Add sub-handlers to the async log handler
- Configure the async log handler settings
- Assign the async log handler to a logger
If you configure this log handler for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add an async log handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/async-handler=ASYNC_HANDLER_NAME:add(queue-length=QUEUE_LENGTH)
/subsystem=logging/async-handler=ASYNC_HANDLER_NAME:add(queue-length=QUEUE_LENGTH)
NoteWhen you add an async log handler, specify the queue length, which is the maximum number of log requests that can be held in the queue at any given time.
Add a sub-handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/async-handler=ASYNC_HANDLER_NAME:add-handler(name=HANDLER_NAME)
/subsystem=logging/async-handler=ASYNC_HANDLER_NAME:add-handler(name=HANDLER_NAME)
NoteYou can add one or more handlers as sub-handlers for this async log handler. The handlers must already exist in the configuration or this command will fail.
You can set one or more of the following async log handler attributes based on your needs:
Set the log level for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/async-handler=ASYNC_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
/subsystem=logging/async-handler=ASYNC_HANDLER_NAME:write-attribute(name=level,value=LEVEL)
The default is
ALL
.Set the overflow action by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/async-handler=ASYNC_HANDLER_NAME:write-attribute(name=overflow-action,value=OVERFLOW_ACTION)
/subsystem=logging/async-handler=ASYNC_HANDLER_NAME:write-attribute(name=overflow-action,value=OVERFLOW_ACTION)
The default value is
BLOCK
, which means that threads will block if the queue is full. You can change this value toDISCARD
, which means that the oldest log messages will be deleted to accommodate new messages in the event of a full queue.Set the filter expression by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/async-handler=ASYNC_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
/subsystem=logging/async-handler=ASYNC_HANDLER_NAME:write-attribute(name=filter-spec, value=FILTER_EXPRESSION)
Specify the expression to filter log messages for the handler. Escape any commas and quotation marks, and surround the expression with quotation marks. For example, replace the
FILTER_EXPRESSION
variable with"not(match(\"WFLY\"))"
to create a filter expression ofnot(match("WFLY"))
.
Assign the async log handler to a logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=ASYNC_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:add-handler(name=ASYNC_HANDLER_NAME)
To activate the log handler, you can assign the async log handler to the root logger or any other logger.
If needed, you can remove an async log handler by using the
remove
operation with the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/async-handler=ASYNC_HANDLER_NAME:remove
/subsystem=logging/async-handler=ASYNC_HANDLER_NAME:remove
NoteYou can remove a log handler when it is no longer required for your logging configuration. However, a log handler cannot be removed if it is currently assigned to a logger.
Additional resources
10.6. Configuring the root logger
The root logger captures all log messages of the specified log level or higher sent to the server that are not captured by a log category.
You can configure the root logger in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, and selecting Root Logger.
If you configure this log handler for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Assign the log handlers to the root logger by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:add-handler(name=LOG_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:add-handler(name=LOG_HANDLER_NAME)
If needed, you can remove the root handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:remove-handler(name=LOG_HANDLER_NAME)
/subsystem=logging/root-logger=ROOT:remove-handler(name=LOG_HANDLER_NAME)
NoteYou can remove a log handler when it is no longer required for your logging configuration.
Set the log level for the handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/root-logger=ROOT:write-attribute(name=level,value=LEVEL)
/subsystem=logging/root-logger=ROOT:write-attribute(name=level,value=LEVEL)
Additional resources
10.7. Configuring log formatters
A log formatter defines the appearance of log messages from the handler.
The logging
subsystem lets you configure the following types of log formatters:
10.7.1. Configuring a pattern formatter
You can create a named pattern formatter to use across log handlers to format log messages.
You can configure a pattern formatter in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, selecting Formatter and then choosing the Pattern Formatter option.
If you configure this log formatter for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Create a pattern formatter by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/pattern-formatter=PATTERN_FORMATTER_NAME:add(pattern=PATTERN)
/subsystem=logging/pattern-formatter=PATTERN_FORMATTER_NAME:add(pattern=PATTERN)
When defining a pattern formatter, provide a pattern string to format log messages. For example, the default configuration uses the following log formatter string for server log messages:
%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n
.Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 2016-03-18 15:49:32,075 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
2016-03-18 15:49:32,075 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
Set the color map for a pattern formatter by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/pattern-formatter=PATTERN_FORMATTER_NAME:write-attribute(name=color-map,value="LEVEL:COLOR,LEVEL:COLOR")
/subsystem=logging/pattern-formatter=PATTERN_FORMATTER_NAME:write-attribute(name=color-map,value="LEVEL:COLOR,LEVEL:COLOR")
Define a color map to assign a color to different log levels. The format is a comma-separated list of
LEVEL:COLOR
.-
Valid levels:
finest
,finer
,fine
,config
,trace
,debug
,info
,warning
,warn
,error
,fatal
,severe
-
Valid colors:
black
,green
,red
,yellow
,blue
,magenta
,cyan
,white
,brightblack
,brightred
,brightgreen
,brightblue
,brightyellow
,brightmagenta
,brightcyan
,brightwhite
-
Valid levels:
Additional resources
10.7.2. Configuring a JSON log formatter
You can create a JSON log formatter to format log messages in JSON.
You can configure a JSON log formatter in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, selecting Formatter and then choosing the JSON Formatter option.
If you configure this log formatter for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add a JSON log formatter.
Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/json-formatter=JSON_FORMATTER_NAME:add(pretty-print=true, exception-output-type=formatted)
/subsystem=logging/json-formatter=JSON_FORMATTER_NAME:add(pretty-print=true, exception-output-type=formatted)
Expected output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow { "timestamp": "2018-10-18T13:53:43.031-04:00", "sequence": 62, "loggerClassName": "org.jboss.as.server.logging.ServerLogger_$logger", "loggerName": "org.jboss.as", "level": "INFO", "message": "WFLYSRV0025: JBoss EAP 8.1.0.GA (WildFly Core 21.0.5.Final-redhat-00001) started in 5227ms - Started 317 of 556 services (343 services are lazy, passive or on-demand), "threadName": "Controller Boot Thread", "threadId": 22, "mdc": { }, "ndc": "", "hostName": "localhost.localdomain", "processName": "jboss-modules.jar", "processId": 7461 }
{ "timestamp": "2018-10-18T13:53:43.031-04:00", "sequence": 62, "loggerClassName": "org.jboss.as.server.logging.ServerLogger_$logger", "loggerName": "org.jboss.as", "level": "INFO", "message": "WFLYSRV0025: JBoss EAP 8.1.0.GA (WildFly Core 21.0.5.Final-redhat-00001) started in 5227ms - Started 317 of 556 services (343 services are lazy, passive or on-demand), "threadName": "Controller Boot Thread", "threadId": 22, "mdc": { }, "ndc": "", "hostName": "localhost.localdomain", "processName": "jboss-modules.jar", "processId": 7461 }
Add a Logstash JSON log formatter by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/json-formatter=logstash:add(exception-output-type=formatted, key-overrides=[timestamp="@timestamp"], meta-data=[@version=1])
/subsystem=logging/json-formatter=logstash:add(exception-output-type=formatted, key-overrides=[timestamp="@timestamp"], meta-data=[@version=1])
NoteYou can modify the JSON log formatter output keys and add static metadata. The primary purpose of the JSON log formatter is to format log messages in JSON. Logstash consumes this JSON output and searches for the
@timestamp
and@version
fields. The following example creates a JSON log formatter that formats messages for Logstash.You can use the JSON formatter attributes as follows:
-
The
key-overrides
attribute overrides the names of the defined keys. -
Format exceptions as objects by setting the
exception-output-type
attribute to formatted. -
Include the exception stack trace by setting the
exception-output-type
attribute todetailed
. -
Format exceptions as objects and include stack traces by setting the
exception-output-type
todetailed-and-formatted
. -
Add metadata to log records using the
meta-data
attribute.
-
The
Additional resources
10.7.3. Configuring an XML log formatter
You can create an XML log formatter to format log messages in XML.
You can configure an XML log formatter in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration
If you configure this log formatter for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add an XML log formatter.
Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/xml-formatter=XML_FORMATTER_NAME:add(pretty-print=true, exception-output-type=detailed-and-formatted)
/subsystem=logging/xml-formatter=XML_FORMATTER_NAME:add(pretty-print=true, exception-output-type=detailed-and-formatted)
Expected output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow <record> <timestamp>2018-10-18T13:55:53.419-04:00</timestamp> <sequence>62</sequence> <loggerClassName>org.jboss.as.server.logging.ServerLogger_$logger</loggerClassName> <loggerName>org.jboss.as</loggerName> <level>INFO</level> <message>WFLYSRV0025: {ProductCurrentVersionExamples} (WildFly Core 10.0.0.Final-redhat-20190924) started in 6271ms - Started 495 of 679 services (331 services are lazy, passive or on-demand)</message> <threadName>Controller Boot Thread</threadName> <threadId>22</threadId> <mdc> </mdc> <ndc></ndc> <hostName>localhost.localdomain</hostName> <processName>jboss-modules.jar</processName> <processId>7790</processId> </record>
<record> <timestamp>2018-10-18T13:55:53.419-04:00</timestamp> <sequence>62</sequence> <loggerClassName>org.jboss.as.server.logging.ServerLogger_$logger</loggerClassName> <loggerName>org.jboss.as</loggerName> <level>INFO</level> <message>WFLYSRV0025: {ProductCurrentVersionExamples} (WildFly Core 10.0.0.Final-redhat-20190924) started in 6271ms - Started 495 of 679 services (331 services are lazy, passive or on-demand)</message> <threadName>Controller Boot Thread</threadName> <threadId>22</threadId> <mdc> </mdc> <ndc></ndc> <hostName>localhost.localdomain</hostName> <processName>jboss-modules.jar</processName> <processId>7790</processId> </record>
Add a key override XML log formatter by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/xml-formatter=XML_FORMATTER_NAME:add(pretty-print=true, print-namespace=true, namespace-uri="urn:custom:1.0", key-overrides={message=msg, record=logRecord, timestamp=date}, print-details=true)
/subsystem=logging/xml-formatter=XML_FORMATTER_NAME:add(pretty-print=true, print-namespace=true, namespace-uri="urn:custom:1.0", key-overrides={message=msg, record=logRecord, timestamp=date}, print-details=true)
You can use the XML formatter attributes as follows:
-
The
key-overrides
attribute overrides the names of the defined keys. -
Format exceptions as objects by setting the
exception-output-type
attribute to formatted. -
Include the exception stack trace by setting the
exception-output-type
attribute todetailed
. -
Format exceptions as objects and include stack traces by setting the
exception-output-type
todetailed-and-formatted
. -
Add metadata to log records using the
meta-data
attribute.
-
The
Additional resources
10.7.4. Configuring a custom log formatter
You can create a custom log formatter to use across log handlers to format log messages.
You can configure a custom log formatter in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Configuration, clicking View, selecting Formatter and then choosing the Custom Formatter option.
If you configure this log formatter for a logging profile, start the command with /subsystem=logging/logging-profile=LOGGING_PROFILE_NAME/
instead of /subsystem=logging/
.
Additionally, if you are running in a managed domain, precede the commands with /profile=PROFILE_NAME
.
Prerequisites
- JBoss EAP is running.
- You have access to the management CLI.
Procedure
Add the custom log formatter by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/custom-formatter=CUSTOM_FORMATTER_NAME:add(class=CLASS_NAME, module=MODULE_NAME)
/subsystem=logging/custom-formatter=CUSTOM_FORMATTER_NAME:add(class=CLASS_NAME, module=MODULE_NAME)
NoteWhen you add a custom log formatter, specify the Java class of the formatter and the JBoss EAP module that contains it. This class must extend
java.util.logging.Formatter
. Ensure you have created a module containing the custom logger or this command will fail.Set the properties for the log formatter by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/custom-formatter=CUSTOM_FORMATTER_NAME:write-attribute(name=properties.PROPERTY_NAME,value=PROPERTY_VALUE)
/subsystem=logging/custom-formatter=CUSTOM_FORMATTER_NAME:write-attribute(name=properties.PROPERTY_NAME,value=PROPERTY_VALUE)
The properties must be accessible using a setter method.
Assign the custom formatter to a log handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/periodic-rotating-file-handler=FILE_HANDLER_NAME:write-attribute(name=named-formatter, value=CUSTOM_FORMATTER_NAME)
/subsystem=logging/periodic-rotating-file-handler=FILE_HANDLER_NAME:write-attribute(name=named-formatter, value=CUSTOM_FORMATTER_NAME)
This command assigns a custom formatter for use by a periodic rotating file handler.
The following example configures a custom XML formatter. It uses the java.util.logging.XMLFormatter
class provided in the org.jboss.logmanager
module and assigns it to the console log handler.
Example
/subsystem=logging/custom-formatter=custom-xml-formatter:add(class=java.util.logging.XMLFormatter, module=java.logging) /subsystem=logging/console-handler=CONSOLE:write-attribute(name=named-formatter, value=custom-xml-formatter)
/subsystem=logging/custom-formatter=custom-xml-formatter:add(class=java.util.logging.XMLFormatter, module=java.logging)
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=named-formatter, value=custom-xml-formatter)
Expected Output
<record> <date>2016-03-23T12:58:13</date> <millis>1458752293091</millis> <sequence>93963</sequence> <logger>org.jboss.as</logger> <level>INFO</level> <class>org.jboss.as.server.BootstrapListener</class> <method>logAdminConsole</method> <thread>22</thread> <message>WFLYSRV0051: Admin console listening on http://%s:%d</message> <param>127.0.0.1</param> <param>9990</param> </record>
<record>
<date>2016-03-23T12:58:13</date>
<millis>1458752293091</millis>
<sequence>93963</sequence>
<logger>org.jboss.as</logger>
<level>INFO</level>
<class>org.jboss.as.server.BootstrapListener</class>
<method>logAdminConsole</method>
<thread>22</thread>
<message>WFLYSRV0051: Admin console listening on http://%s:%d</message>
<param>127.0.0.1</param>
<param>9990</param>
</record>
10.8. Configuring application logging in JBoss EAP
You can configure logging for applications by using the JBoss EAP logging
subsystem or on a per-deployment
basis. The logging
subsystem provides centralized management, while per-deployment
logging enables custom configurations specific to each application.
10.8.1. Per-deployment logging configuration
Per-deployment logging enables developers to configure logging for their applications in advance. When the application is deployed, logging starts according to the defined configuration. The log files generated through this configuration contain information only about the behavior of the application.
When using per-deployment logging, the application does not use the logging
subsystem configuration. Instead, it uses the logging configuration defined within the application’s deployment file. Each application can have custom logging settings, independent of the global configuration.
This approach has advantages and disadvantages compared to system-wide logging. An advantage is that the JBoss EAP administrator does not need to configure any logging other than server logging. A disadvantage is that the per-deployment logging configuration is read only at server startup and cannot be changed at runtime.
Additional resources
10.8.1.1. Disabling per-deployment logging
You can disable per-deployment logging in JBoss EAP by either setting the use-deployment-logging-config
attribute or excluding the logging
subsystem.
Prerequisites
- JBoss EAP is running.
Procedure
Use one of the following methods to disable per-deployment logging:
Set the
use-deployment-logging-config
attribute tofalse
.Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging:write-attribute(name=use-deployment-logging-config,value=false)
/subsystem=logging:write-attribute(name=use-deployment-logging-config,value=false)
The
use-deployment-logging-config
attribute controls whether your deployment is scanned for per-deployment logging. This defaults totrue
. Set it tofalse
to disable per-deployment logging.-
Exclude the
logging
subsystem by using ajboss-deployment-structure.xml
file.
Additional resources
10.8.2. Application logging profiles
Logging profiles are independent sets of logging configurations that you can assign to deployed applications. Like the regular logging
subsystem, a logging profile can define handlers, categories, formatters, and a root logger. However, it cannot refer to configurations in other profiles or the main logging
subsystem. The design of logging profiles resembles the logging
subsystem for easier configuration.
Logging profiles enable administrators to create logging configurations specific to one or more applications without impacting other configurations. Each profile is defined in the server configuration, allowing changes to the logging setup without requiring the redeployment of affected applications.
Each logging profile can have:
- A unique name. This value is required.
- Any number of log handlers.
- Any number of log categories.
- Up to one root logger.
- Log formatters.
An application can specify the logging profile to use in its MANIFEST.MF
file by setting the Logging-Profile
attribute.
10.8.2.1. Configuring a logging profile
You can configure a logging profile with log handlers, categories, and a root logger. Configuring a logging profile uses the same syntax as configuring the logging
subsystem, except for the following differences:
-
The root configuration path is
/subsystem=logging/logging-profile=NAME
. - A logging profile cannot contain other logging profiles.
The
logging
subsystem includes the following attributes that are not available for a logging profile:-
add-logging-api-dependencies
-
use-deployment-logging-config
-
You can configure a Logging profiles in JBoss EAP by using the management CLI. Alternatively, you can configure them through the management console by navigating to Configuration > Subsystems > Logging > Logging Profiles.
Prerequisites
- JBoss EAP is running.
Procedure
Create the logging profile by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logging-profile=PROFILE_NAME:add
/subsystem=logging/logging-profile=PROFILE_NAME:add
Add the file handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logging-profile=PROFILE_NAME/file-handler=FILE_HANDLER_NAME:add(file={path=>"LOG_NAME.log", "relative-to"=>"jboss.server.log.dir"})
/subsystem=logging/logging-profile=PROFILE_NAME/file-handler=FILE_HANDLER_NAME:add(file={path=>"LOG_NAME.log", "relative-to"=>"jboss.server.log.dir"})
Set the logging level for the file handler by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logging-profile=PROFILE_NAME/file-handler=FILE_HANDLER_NAME:write-attribute(name="level", value="DEBUG")
/subsystem=logging/logging-profile=PROFILE_NAME/file-handler=FILE_HANDLER_NAME:write-attribute(name="level", value="DEBUG")
Create the logger name by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logging-profile=PROFILE_NAME/logger=CATEGORY_NAME:add(level=TRACE)
/subsystem=logging/logging-profile=PROFILE_NAME/logger=CATEGORY_NAME:add(level=TRACE)
Assign the file handler to the category by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logging-profile=PROFILE_NAME/logger=CATEGORY_NAME:add-handler(name="FILE_HANDLER_NAME")
/subsystem=logging/logging-profile=PROFILE_NAME/logger=CATEGORY_NAME:add-handler(name="FILE_HANDLER_NAME")
You can then set the logging profile to use by an application in its MANIFEST.MF
file.
10.8.2.2. Application logging profile configuration example
This example shows the configuration of a logging profile and the application that uses it. It includes the management CLI commands, the resulting XML, and the application’s MANIFEST.MF
file.
The example logging profile has the following characteristics:
-
The name is
accounts-app-profile
. -
The log category is
com.company.accounts.ejbs
. -
The log level is
TRACE
. -
The log handler is a file handler using the file
ejb-trace.log
.
Management CLI Session
/subsystem=logging/logging-profile=accounts-app-profile:add /subsystem=logging/logging-profile=accounts-app-profile/file-handler=ejb-trace-file:add(file={path=>"ejb-trace.log", "relative-to"=>"jboss.server.log.dir"}) /subsystem=logging/logging-profile=accounts-app-profile/file-handler=ejb-trace-file:write-attribute(name="level", value="DEBUG") /subsystem=logging/logging-profile=accounts-app-profile/logger=com.company.accounts.ejbs:add(level=TRACE) /subsystem=logging/logging-profile=accounts-app-profile/logger=com.company.accounts.ejbs:add-handler(name="ejb-trace-file")
/subsystem=logging/logging-profile=accounts-app-profile:add
/subsystem=logging/logging-profile=accounts-app-profile/file-handler=ejb-trace-file:add(file={path=>"ejb-trace.log", "relative-to"=>"jboss.server.log.dir"})
/subsystem=logging/logging-profile=accounts-app-profile/file-handler=ejb-trace-file:write-attribute(name="level", value="DEBUG")
/subsystem=logging/logging-profile=accounts-app-profile/logger=com.company.accounts.ejbs:add(level=TRACE)
/subsystem=logging/logging-profile=accounts-app-profile/logger=com.company.accounts.ejbs:add-handler(name="ejb-trace-file")
XML Configuration
<logging-profiles> <logging-profile name="accounts-app-profile"> <file-handler name="ejb-trace-file"> <level name="DEBUG"/> <file relative-to="jboss.server.log.dir" path="ejb-trace.log"/> </file-handler> <logger category="com.company.accounts.ejbs"> <level name="TRACE"/> <handlers> <handler name="ejb-trace-file"/> </handlers> </logger> </logging-profile> </logging-profiles>
<logging-profiles>
<logging-profile name="accounts-app-profile">
<file-handler name="ejb-trace-file">
<level name="DEBUG"/>
<file relative-to="jboss.server.log.dir" path="ejb-trace.log"/>
</file-handler>
<logger category="com.company.accounts.ejbs">
<level name="TRACE"/>
<handlers>
<handler name="ejb-trace-file"/>
</handlers>
</logger>
</logging-profile>
</logging-profiles>
Application MANIFEST.MF file
Manifest-Version: 1.0 Logging-Profile: accounts-app-profile
Manifest-Version: 1.0
Logging-Profile: accounts-app-profile
10.8.3. Viewing deployment logging configuration
You can view the logging configuration of a deployment in JBoss EAP by using the management CLI.
Prerequisites
- JBoss EAP is running.
Procedure
Retrieve the logging configuration for a specific deployment by using the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /deployment=DEPLOYMENT_NAME/subsystem=logging/configuration=CONFIG:read-resource
/deployment=DEPLOYMENT_NAME/subsystem=logging/configuration=CONFIG:read-resource
The
CONFIG
value can be one of the following:-
default
: If the deployment is using thelogging
subsystem, this will output the logging subsystem configuration. -
profile-PROFILE_NAME
: If the deployment is using a logging profile defined in the logging subsystem, this will output the logging profile configuration. -
The path to the configuration file being used, for example,
myear.ear/META-INF/logging.properties
.
-
To display the configuration for a specific logging profile, run the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /deployment=mydeployment.war/subsystem=logging/configuration=profile-MYPROFILE:read-resource(recursive=true,include-runtime=true)
/deployment=mydeployment.war/subsystem=logging/configuration=profile-MYPROFILE:read-resource(recursive=true,include-runtime=true)
This command retrieves the configuration for the
MYPROFILE
logging profile, which is used by the specified deployment.Expected output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow { "outcome" => "success", "result" => { "error-manager" => undefined, "filter" => undefined, "formatter" => { "MYFORMATTER" => { "class-name" => "org.jboss.logmanager.formatters.PatternFormatter", "module" => undefined, "properties" => {"pattern" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"} } }, "handler" => { "MYPERIODIC" => { "class-name" => "org.jboss.logmanager.handlers.PeriodicRotatingFileHandler", "encoding" => undefined, "error-manager" => undefined, "filter" => undefined, "formatter" => "MYFORMATTER", "handlers" => [], "level" => "ALL", "module" => undefined, "properties" => { "append" => "true", "autoFlush" => "true", "enabled" => "true", "suffix" => ".yyyy-MM-dd", "fileName" => "EAP_HOME/standalone/log/deployment.log" } } }, "logger" => {"MYCATEGORY" => { "filter" => undefined, "handlers" => [], "level" => "DEBUG", "use-parent-handlers" => true }}, "pojo" => undefined } }
{ "outcome" => "success", "result" => { "error-manager" => undefined, "filter" => undefined, "formatter" => { "MYFORMATTER" => { "class-name" => "org.jboss.logmanager.formatters.PatternFormatter", "module" => undefined, "properties" => {"pattern" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"} } }, "handler" => { "MYPERIODIC" => { "class-name" => "org.jboss.logmanager.handlers.PeriodicRotatingFileHandler", "encoding" => undefined, "error-manager" => undefined, "filter" => undefined, "formatter" => "MYFORMATTER", "handlers" => [], "level" => "ALL", "module" => undefined, "properties" => { "append" => "true", "autoFlush" => "true", "enabled" => "true", "suffix" => ".yyyy-MM-dd", "fileName" => "EAP_HOME/standalone/log/deployment.log" } } }, "logger" => {"MYCATEGORY" => { "filter" => undefined, "handlers" => [], "level" => "DEBUG", "use-parent-handlers" => true }}, "pojo" => undefined } }
You can also perform a recursive
read-resource
operation to retrieve the entire logging configuration and other information about a deployment, by using the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow /deployment=DEPLOYMENT_NAME/subsystem=logging:read-resource(include-runtime=true, recursive=true)
/deployment=DEPLOYMENT_NAME/subsystem=logging:read-resource(include-runtime=true, recursive=true)
Additional resources
10.9. Logging subsystem performance management
You can optimize and monitor the performance of the logging
subsystem to ensure efficient logging and resource management. Regular monitoring helps identify potential issues before they impact performance.
Additional resources