14.3.6. Configure a Size Log Handler in the CLI

Size rotated file log handlers can be added, removed and edited in the CLI.
The tasks you will perform to configure a size rotated file log handler are:
  • Add a new log handler.
  • Display the configuration of the log handler
  • Set the handler's log level.
  • Set the handler's appending behavior.
  • Set whether the handler uses autoflush or not.
  • Set the encoding used for the handler's output.
  • Specify the file to which the log handler will write.
  • Set the formatter used for the handler's output.
  • Set the maximum size of each log file
  • Set the maximum number of backup logs to keep
  • Set the rotate on boot option for the size rotation file handler
  • Remove a log handler.
Each of these tasks are described below.

Important

When configuring a log handler in a logging profile the root of the configuration path is /subsystem=logging/logging-profile=NAME/ instead of /subsystem=logging/.
Add a new log handler
Use the add operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:add(file={"path"=>"PATH", "relative-to"=>"DIR"}) 
Replace HANDLER with the name of the log handler. Replace PATH with the filename for the file that the log is being written to. Replace DIR with the name of the directory where the file is to be located. The value of DIR can be a path variable.

Example 14.39. Add a new log handler

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:add(file={"path"=>"accounts_trace.log", "relative-to"=>"jboss.server.log.dir"}) 
{"outcome" => "success"}
Display the configuration of the log handler
Use the read-resource operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:read-resource 
Replace HANDLER with the name of the log handler.

Example 14.40. Display the configuration of the log handler

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:read-resource
{
    "outcome" => "success",
    "result" => {
        "append" => true,
        "autoflush" => true,
        "encoding" => undefined,
        "file" => {
            "path" => "accounts_trace.log",
            "relative-to" => "jboss.server.log.dir"
        },
        "filter" => undefined,
        "formatter" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
        "level" => undefined,
        "max-backup-index" => 1,
        "rotate-size" => "2m"
    }
}
[standalone@localhost:9999 /]
Set the handler's log level
Use the write-attribute operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:write-attributel(name="level", value="LOG_LEVEL_VALUE") 
Replace HANDLER with the name of the log handler. Replace LOG_LEVEL_VALUE with the log level that is to be set.

Example 14.41. Set the handler's log level

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:write-attribute(name="level", value="TRACE")
{"outcome" => "success"}
[standalone@localhost:9999 /]
Set the handler's appending behavior
Use the write-attribute operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:write-attribute(name="append", value="BOOLEAN") 
Replace HANDLER with the name of the log handler. Replace BOOLEAN with false if you required that a new log file be created each time the application server is launched. Replace BOOLEAN with true if the application server should continue to use the same file.
JBoss EAP 6 must be restarted for this change to take effect.

Example 14.42. Set the handler's appending behavior

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:write-attribute(name="append", value="true")
{
    "outcome" => "success",
    "response-headers" => {
        "operation-requires-reload" => true,
        "process-state" => "reload-required"
    }
}
[standalone@localhost:9999 /]
Set whether the handler uses autoflush or not
Use the write-attribute operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:write-attribute(name="autoflush", value="BOOLEAN") 
Replace HANDLER with the name of the log handler. Replace BOOLEAN with true if this handler is to immediately write its output.

Example 14.43. Set whether the handler uses autoflush or not

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:write-attribute(name="autoflush", value="true")
{"outcome" => "success"}
[standalone@localhost:9999 /]
Set the encoding used for the handler's output
Use the write-attribute operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:write-attribute(name="encoding", value="ENCODING") 
Replace HANDLER with the name of the log handler. Replace ENCODING with the name of the required character encoding system.

Example 14.44. Set the encoding used for the handler's output

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:write-attribute(name="encoding", value="utf-8") 
{"outcome" => "success"}]
Specify the file to which the log handler will write
Use the write-attribute operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:write-attribute(name="file", value={"path"=>"PATH", "relative-to"=>"DIR"}) 
Replace HANDLER with the name of the log handler. Replace PATH with the filename for the file that the log is being written to. Replace DIR with the name of the directory where the file is to be located. The value of DIR can be a path variable.

Example 14.45. Specify the file to which the log handler will write

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:write-attribute(name="file", value={"path"=>"accounts_trace.log", "relative-to"=>"jboss.server.log.dir"}) 
{"outcome" => "success"}
Set the formatter used for the handler's output
Use the write-attribute operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:write-attribute(name="formatter", value="FORMATTER") 
Replace HANDLER with the name of the log handler. Replace FORMAT with the required formatter string.

Example 14.46. Set the formatter used for the handler's output

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:write-attribute(name="formatter", value="%d{HH:mm:ss,SSS} %-5p (%c) [%t] %s%E%n")
{"outcome" => "success"}
Set the maximum size of each log file
Use the write-attribute operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:write-attribute(name="rotate-size", value="SIZE") 
Replace HANDLER with the name of the log handler. Replace SIZE with maximum file size.

Example 14.47. Set the maximum size of each log file

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:write-attribute(name="rotate-size", value="50m")  
{"outcome" => "success"}
[standalone@localhost:9999 /]
Set the maximum number of backup logs to keep
Use the write-attribute operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:write-attribute(name="max-backup-index", value="NUMBER") 
Replace HANDLER with the name of the log handler. Replace NUMBER with the required number of log files to keep.

Example 14.48. Set the maximum number of backup logs to keep

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:write-attribute(name="max-backup-index", value="5")
{"outcome" => "success"}
[standalone@localhost:9999 /]
Set the rotate-on-boot option on the size-rotating-file-handler
This option is only available for the size-rotating-file-handler file handler. It defaults to false, meaning a new log file is not created on server restart.
To change it, use the write-attribute operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:write-attribute(name="rotate-on-boot", value="BOOLEAN") 
Replace HANDLER with the name of the size-rotating-file-handler log handler. Replace BOOLEAN with true if a new size-rotating-file-handler log file should be created on restart.

Example 14.49. Specify to create a new size-rotating-file-handler log file on server restart

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:write-attribute(name="rotate-on-boot", value="true")
{"outcome" => "success"}
[standalone@localhost:9999 /]
Remove a log handler
Use the remove operation with the following syntax.
 /subsystem=logging/size-rotating-file-handler=HANDLER:remove 
Replace HANDLER with the name of the log handler.

Example 14.50. Remove a log handler

[standalone@localhost:9999 /] /subsystem=logging/size-rotating-file-handler=ACCOUNTS_TRACE:remove
{"outcome" => "success"}