Analysis of the ServiceMix logs is a main source of information regarding the current state of your system. This recipe will show you how to effectively display logs generated by the ServiceMix container.
The default location of the ServiceMix logfile is SERVICEMIX_HOME/data/log/servicemix.log
. You can open this file with your favorite text editor and check that the running ServiceMix instance tells you pretty much about its activity by adding interesting records to its logfile. Unfortunately, logfiles tend to get extremely large as the application continues to append new records to the log. This is the reason why opening logfiles in text editors is considered as a bad practice—the majority of the text editors do not handle large text files well; especially when some other process is still appending to the latter file.
Instead of opening the log in the text editor, we tail it, that is, display only a certain number of lines from the end of the file.
Connect to your ServiceMix instance with the interactive Karaf console.
Enter the
log:tail
command in the Karaf shell.Press Ctrl + C to stop displaying the logs.
The usual method of displaying application logs is to use Unix's tail
command. This command, however, is natively available only for Unix systems. The ServiceMix method of checking its own logs is to use the tail
command available in the interactive console.
The log:tail
command available in the ServiceMix console works similar to the tail -f
command available under Unix systems. It displays the last lines of the logfiles and continues to show the new ones appended to the file, as shown here:
2012-06-23 21:41:42,589 | INFO | rint Extender: 1 | KarArtifactInstaller | ? ? | 42 - org.apache.karaf.deployer.kar - 2.2.4 | Karaf archives will be extracted to /home/hekonsek/Desktop/apache-servicemix-4.4.2/local-repo 2012-06-23 21:41:42,590 | INFO | rint Extender:1 | KarArtifactInstaller | ? ? | 42 - org.apache.karaf.deployer.kar - 2.2.4 | Timestamps for Karafarchives will be extracted to /home/hekonsek/Desktop/apache-servicemix-4.4.2/local-repo/.timestamps 2012-06-23 21:41:42,637 | INFO | FelixStartLevel | ultOsgiApplicationContextCreator | ? ? | 76 - org.springframework.osgi.extender - 1.2.1 | Discovered configurations {osgibundle:/META-INF/spring/*.xml} in bundle [Apache CXF Bundle Jar (org.apache.cxf.bundle)]To stop displaying the log,press Ctrl+C. The ServiceMix console will stop processing the log file and will return to the prompt. 2012-06-23 21:41:52,178 | INFO | rint Extender: 3 | TransportServerThreadSupport | ? ? | 50 -org.apache.activemq.activemq-core - 5.5.1 | Listening for connections at: stomp://localhost:616132012-06-23 21:41:52,179 | INFO | rint Extender: 3 | TransportConnector | ? ? | 50 - org.apache.activemq.activemq-core - 5.5.1 | Connector stomp Started 2012-06-23 21:41:52,180 |INFO | rint Extender: 3 | BrokerService | ? ? | 50 - org.apache.activemq.activemq-core - 5.5.1 |ActiveMQ JMS Message Broker (default, ID:drone-49934-1340480512024-0:1) started ^C karaf@root>
The tail of the file includes the last records from the ServiceMix log, to which the container appends by default. Even if the logfile is very long, the tail
command displays only the most recent lines. The tailed logfile will also be monitored for new records, which will be displayed on the screen as they appear.
One particularly interesting use case when working with the logfile is to show the last exception that occurred in the system. This can be done with the log:display-exception
command. If your application is healthy, then this command should return no results annotated with the recent timestamp. If a new stacktrace appears, then you should examine it, fix the bug, and deploy the patched module to the ServiceMix container (or improve the exception handling).
Don't be afraid to use the ServiceMix tail
command with the popular parameters available for the Linux command line. For example, you can use the -n 200
option to display the last 200 lines from the logfile. Also keep in mind that you can see all the options available for tail
by typing the log:tail –help
command.