Book Image

Instant Apache ServiceMix How-to

By : Henryk Konsek
Book Image

Instant Apache ServiceMix How-to

By: Henryk Konsek

Overview of this book

<p>Creating reliable integration solution can be easy if you choose the right tools for the job. Apache Camel and ServiceMix are the leading integration technologies dedicated to dealing with the complexity of the messaging solutions. Learn how to efficiently integrate multiple systems with bleeding edge open source Apache software.</p> <p>"Instant Apache ServiceMix How-to" is a practical, hands-on guide that provides you with a number of clear, step-by-step exercises that will help you take advantage of the real power that is behind the leading Apache integration stack.</p> <p>This book guides the reader in how to install ServiceMix and how to get it up and running. It will take you through a number of practical recipes – starting with the basic commands of Apache Karaf container and ending with the deployment of JMS and web service solutions.</p>
Table of Contents (7 chapters)

Displaying the ServiceMix log (Must know)


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.

Getting ready

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.

How to do it...

  1. Connect to your ServiceMix instance with the interactive Karaf console.

  2. Enter the log:tail command in the Karaf shell.

  3. Press Ctrl + C to stop displaying the logs.

How it works...

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.

There's more...

Displaying the last exception

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).

Additional tail options

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.