In this short tutorial we will learn how to inspect the WildFly log files from the Command Line Interface. 

One interesting feature is the ability to display log files using the management instruments. Although log files are typically read and filtered using your operating system shell commands (such as tail or grep), the final release of WildFly enabled listing and reading the log files via the CLI as well. Gathering information from server log files is quite intuitive, for example in order to get the list of the server log files, simply execute the list-log-files command on 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 for us, 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 full server.log file:

/subsystem=logging/:read-log-file(name=server.log,lines=-1,skip=0)
{
"outcome" => "success",
"result" => [
. . . . . .
"2014-02-16 21:53:19,520 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management",
"2014-02-16 21:53:19,523 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990",
"2014-02-16 21:53:19,525 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.0.0.Final \"WildFly\" started in 38820ms - Started 305 of 361 services (93 services are lazy, passive or on-demand)"
. . . .
]
}


If you want to emulate Linux tail command, you can add the "tail" parameter which accepts a boolean. Here's for example how to read the last 10 lines of the server.log

/subsystem=logging/:read-log-file(name=server.log,tail=true,lines=10,skip=0)
{
"outcome" => "success",
"result" => [
"",
"2014-02-17 15:01:25,100 INFO [org.jboss.weld.deployer] (MSC service thread 1-8) JBAS016005: Starting Services for CDI deployment: rest-javaee7.war",
"2014-02-17 15:01:25,292 INFO [org.jboss.weld.Version] (MSC service thread 1-8) WELD-000900: 2.1.2 (Final)",
"2014-02-17 15:01:25,523 INFO [org.jboss.weld.deployer] (MSC service thread 1-6) JBAS016008: Starting weld service for deployment rest-javaee7.war",
"2014-02-17 15:01:29,366 INFO [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-7) Deploying javax.ws.rs.core.Application: class com.sample.JaxRsActivator",
"2014-02-17 15:01:29,541 INFO [org.wildfly.extension.undertow] (MSC service thread 1-7) JBAS017534: Registered web context: /rest-javaee7",
"2014-02-17 15:01:29,583 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS018559: Deployed \"rest-javaee7.war\" (runtime-name : \"rest-javaee7.war\")",
"2014-02-17 15:01:29,726 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management",
"2014-02-17 15:01:29,729 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990",
"2014-02-17 15:01:29,730 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.0.0.Final \"WildFly\" started in 45032ms - Started 305 of 3
61 services (93 services are lazy, passive or on-demand)"
]
}

Reading WildFly logs from HTTP

WildFly allows you to use the HTTP channel to stream server logs from a remote location. This can be useful if you want to perform some filtering/operations on the content of log files remotely. You can test it by opening the browser and issuing the following:

 

http://localhost:9990/management/subsystem/logging/log-file/server.log?operation=attribute&name=stream&useStreamAsResponse&user=admin&password=mYpassword1!

 

Replace the user and password attribute in the previous URL with a management user and password. You should expect your browser to request whether you are going to open the log file or save it locally.

A more programmatic approach consists in using a utility such as curl to request the log file

and save it locally. This offers the benefit that you can choose the log format (in our

example, JSON):

curl --digest -L -D - http://127.0.0.1:9990/management?useStreamAsResponse \
--header "Content-Type: application/json" -u admin:mYpassword1! \
-d '{"operation":"read-attribute","address":[{"subsystem":"logging"},{"log-file":"server.log"}],"name":"stream"}'

 

0
0
0
s2smodern

W

i

l

d

F

l

y

 

c

h

e

a

t

s

h

e

e

t