Loading...

Change default log format of JBoss via CLI

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

This blog post demonstrates how to change the default log format of JBoss periodic file handler FILE. In the original state, it doesn’t log the date of the log entry. Using logstash with datetime matching, requires a date :-).

Connect with the CLI to your JBoss installation. Check if the file handler is there:

[standalone@localhost:9999 /] /subsystem=logging/periodic-rotating-file-handler=FILE:read-resource
{
    "outcome" => "success",
    "result" => {
        "append" => true,
        "autoflush" => true,
        "enabled" => true,
        "encoding" => undefined,
        "file" => {
            "relative-to" => "jboss.server.log.dir",
            "path" => "server.log"
        },
        "filter" => undefined,
        "filter-spec" => undefined,
        "formatter" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
        "level" => "ALL",
        "name" => "FILE",
        "named-formatter" => "PATTERN",
        "suffix" => ".yyyy-MM-dd"
    }
}

Change the log format with

/subsystem=logging/periodic-rotating-file-handler=FILE:write-attribute(name="formatter",value="%d{yyyy-MM-dd'T'HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n")

Check the new defined log format

[standalone@localhost:9999 /] /subsystem=logging/periodic-rotating-file-handler=FILE:read-resource
{
    "outcome" => "success",
    "result" => {
        "append" => true,
        "autoflush" => true,
        "enabled" => true,
        "encoding" => undefined,
        "file" => {
            "relative-to" => "jboss.server.log.dir",
            "path" => "server.log"
        },
        "filter" => undefined,
        "filter-spec" => undefined,
        "formatter" => "%d{yyyy-MM-dd'T'HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
        "level" => "ALL",
        "name" => "FILE",
        "named-formatter" => undefined,
        "suffix" => ".yyyy-MM-dd"
    }
}
Please remember the terms for blog comments.