13.3.2. Configure a Log Category in the CLI

Log categories can be added, removed and edited in the CLI.
The main tasks you will perform to configure a log category are:
  • Add a new log category.
  • Display the configuration of a log category.
  • Set the log level.
  • Add log handlers to a log category.
  • Remove log handlers from a log category.
  • Remove a log category.

Important

When configuring a log category in a logging profile, the root of the configuration path is /subsystem=logging/logging-profile=NAME/ instead of /subsystem=logging/.
Add a log category
Use the add operation with the following syntax. Replace CATEGORY with the category to be added.
 /subsystem=logging/logger=CATEGORY:add 

Example 13.5. Adding a new log category

[standalone@localhost:9999 /] /subsystem=logging/logger=com.company.accounts.rec:add   
{"outcome" => "success"}
[standalone@localhost:9999 /]
Display a log category configuration
Use the read-resource operation with the following syntax. Replace CATEGORY with the name of the category.
 /subsystem=logging/logger=CATEGORY:read-resource 

Example 13.6. Log Category read-resource operation

[standalone@localhost:9999 /] /subsystem=logging/logger=org.apache.tomcat.util.modeler:read-resource
{
    "outcome" => "success",
    "result" => {
        "filter" => undefined,
        "handlers" => undefined,
        "level" => "WARN",
        "use-parent-handlers" => true
    }
}
[standalone@localhost:9999 /]
Set the log level
Use the write-attribute operation with the following syntax. Replace CATEGORY with the name of the log category and LEVEL with the log level that is to be set.
 /subsystem=logging/logger=CATEGORY:write-attribute(name="level", value="LEVEL") 

Example 13.7. Setting a log level

[standalone@localhost:9999 /] /subsystem=logging/logger=com.company.accounts.rec:write-attribute(name="level", value="DEBUG")
{"outcome" => "success"}
[standalone@localhost:9999 /]
Set the log category to use the log handlers of the root logger.
Use the write-attribute operation with the following syntax. Replace CATEGORY with the name of the log category. Replace BOOLEAN with true for this log category to use the handlers of the root logger. Replace it with false if it is to use only its own assigned handlers.
 /subsystem=logging/logger=CATEGORY:write-attribute(name="use-parent-handlers", value="BOOLEAN") 

Example 13.8. Setting use-parent-handlers

[standalone@localhost:9999 /] /subsystem=logging/logger=com.company.accounts.rec:write-attribute(name="use-parent-handlers", value="true")
{"outcome" => "success"}
[standalone@localhost:9999 /]
Add a log handlers to a log category
Use the assign-handler operation with the following syntax. Replace CATEGORY with the name of the category and HANDLER with the name of the handler to be added.
 /subsystem=logging/logger=CATEGORY:assign-handler(name="HANDLER") 
The log handler must already have been created before it can be added to the root logger.

Example 13.9. Adding a log handler

[standalone@localhost:9999 /] /subsystem=logging/logger=com.company.accounts.rec:assign-handler(name="AccountsNFSAsync")
{"outcome" => "success"}
[standalone@localhost:9999 /]
Remove a log handler from a log category
Use the unassign-handler operation with the following syntax. Replace CATEGORY with the name of the category and HANDLER with the name of the log handler to be removed.
 /subsystem=logging/logger=CATEGORY:unassign-handler(name="HANDLER") 

Example 13.10. Removing a log handler

[standalone@localhost:9999 /] /subsystem=logging/root-logger=ROOT:root-logger-unassign-handler(name="AccountsNFSAsync")
{"outcome" => "success"}
[standalone@localhost:9999 /]
Remove a category
Use the remove operation with the following syntax. Replace CATEGORY with the name of the category to be removed.
 /subsystem=logging/logger=CATEGORY:remove 

Example 13.11. Removing a log category

[standalone@localhost:9999 /] /subsystem=logging/logger=com.company.accounts.rec:remove   
{"outcome" => "success"}
[standalone@localhost:9999 /]