Over a million developers have joined DZone.

Automatically Include Revision in Log Statement

· Java Zone

Discover how AppDynamics steps in to upgrade your performance game and prevent your enterprise from these top 10 Java performance problems, brought to you in partnership with AppDynamics.

When there is a problem with your software, the first thing you usually ask for is a log showing what happened (provided you write debuggable code), and the version of the software that was running. But it is easy to have the revision of the software automatically added to the log.

In the class Call.java, the subversion revision number is automatically stored at every commit using the following syntax:

// Don't change, auto-updated by svn on check-in
final static String revision = "$Revision: 135264 $";

When printing to the log the first time for a call, the revision information is added:

private void printTraceHeader(String message) {
if (!initialTracePrinted) {
initialTracePrinted = true;

The beginning of a call log looks like this:

-- 17, callcontrol: $Revision: 135264 $

-- 18, callcontrol: Processing MOC IDP, protocol=CAP_V2,
   profile=Profile7.6, layer=callcontrol@tsmr2

-- 18, callcontrol: Trace already activated before call control.

-- 19, callhomerouting: Check if call should be home
   routed, location: 46702000000

-- 19, callhomerouting: Location 46702000000 not configured
   in table, so don't home route.

The first printed line in the log shows that the version of Call.java used was 135264. Every line in the log also contains a relative time stamp (in milliseconds) and the module name, in addition to the actual message. And yes, we still use subversion at work, but I am sure the same information can be included from git as well.

I have been using this simple addition to the logs for a long time, and it has been helpful many times in the past. Every time you check in a new version, the revision variable is updated automatically. If you are not already using this, give it a try. It is quick to set up, and you never again have to wonder which revision was used.

The Java Zone is brought to you in partnership with AppDynamics. AppDynamics helps you gain the fundamentals behind application performance, and implement best practices so you can proactively analyze and act on performance problems as they arise, and more specifically with your Java applications. Start a Free Trial.


Published at DZone with permission of Henrik Warne, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}