WildFly CLI Tech Tip #2: How to read and download log files from the CLI

Gathering information from server log files using WildFly CLI is quite simple; for example in order to get the list of the server log files, simply execute the list-log-files command against the logging subsystem.

/subsystem=logging/:list-log-files
{
    "outcome" => "success",
    "result" => [
        {
            "file-name" => "server.log",
            "file-size" => 9695L,
            "last-modified-date" => "2014-02-13T15:46:04.365+0100"
        },
        {
            "file-name" => "server.log.2014-02-12",
            "file-size" => 9695L,
            "last-modified-date" => "2014-02-12T21:32:49.759+0100"
        }
    ]
}

Another interesting option, is the ability to display the actual log files content filtered by some parameters such as the number of lines to read (lines parameter) and the lines to skip (skip parameter) from the header. Here’s how to read the first 10 lines from the server.log file:

/subsystem=logging/:read-log-file(name=server.log,lines=10,skip=0)
{
    "outcome" => "success",
    "result" => [
        "2014-02-13 15:04:37,017 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017525: Started server default-server.",
        "2014-02-13 15:04:37,041 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) JBAS017531: Host default-host starting",
        "2014-02-13 15:04:37,327 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) JBAS017519: Undertow HTTP listener default listening on /127.0.0.1:8080",}

If you want a full read of your log file, simply provide -1 as argument to the “lines” parameter.

Additionally, it is worth mentioning that you can check your log files also through the attachment CLI command, which has options both for displaying files and save them locally.

Here is how to display the content of server.log file using the attachment command:

attachment display --operation=/subsystem=logging/log-file=server.log:read-resource(include-runtime)

And here is how to save it locally:

attachment save --operation=/subsystem=logging/log-file=server.log:read-resource(include-runtime) --file=./server.log