/*
 * Copyright 2014 Nastel Technologies, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nastel.jkool.tnt4j.format;

import com.nastel.jkool.tnt4j.tracker.TrackingActivity;
import com.nastel.jkool.tnt4j.tracker.TrackingEvent;

/**
 * <p>
 * Simple implementation of <code>Formatter</code> interface provides
 * simple/minimal formatting of <code>TrackingActvity</code> and <code>TrackingEvent</code>
 * as well as any object passed to <code>format()</code> method call.
 * </p>
 * 
 * 
 * @version $Revision: 1 $
 * 
 * @see DefaultFormatter
 * @see TrackingActivity
 * @see TrackingEvent
 */

public class SimpleFormatter extends DefaultFormatter {
	@Override
	public String format(TrackingEvent event) {
		StringBuffer msg = new StringBuffer(1024);
		msg.append("{'").append(event.getSeverity()).append("',");
		msg.append("event='").append(event.getStringMessage()).append("',");
		msg.append("name='").append(event.getOperation().getName()).append("',");
		msg.append("ccode='").append(event.getOperation().getCompCode()).append("',");
		if (event.getOperation().getReasonCode() != 0) {
			msg.append("rcode='").append(event.getOperation().getReasonCode()).append("',");
		}
		if (event.getOperation().getElapsedTime() != 0) {
			msg.append("usec='").append(event.getOperation().getElapsedTime()).append("',");
		}
		if (event.getOperation().getMessageAge() != 0) {
			msg.append("age.usec='").append(event.getOperation().getMessageAge()).append("',");
		}
		if (event.getTag() != null) {
			msg.append("tag='").append(event.getTag()).append("',");
		}
		if (event.getOperation().getCorrelator() != null) {
			msg.append("corr-id='").append(event.getOperation().getCorrelator()).append("',");
		}
		if (event.getOperation().getThrowable() != null) {
			msg.append("error='").append(event.getOperation().getExceptionString()).append("',");
		}
		msg.append("type='").append(event.getOperation().getType()).append("',");
		msg.append("track-id='").append(event.getTrackingId()).append("',");
		if (event.getParentItem() != null) {
			msg.append("parent-id='").append(event.getParentItem().getTrackingId()).append("'");
		}
		msg.append("}");
		return 	msg.toString();
	}
	
	@Override
	public String format(TrackingActivity activity) {
		return activity.getStatus() + "-" + activity.toString();
	}
}

@@ -1175,16 +1175,123 @@
 atter %7B%0A
+%09private static final String SEPARATOR = System.getProperty(%22tnt4j.formatter.simple.separator%22, %22' %7C %22);%0A%09%0A
 %09@Overri
@@ -1429,36 +1429,41 @@
 erity()).append(
-%22',%22
+SEPARATOR
 );%0A%09%09msg.append(
@@ -1505,36 +1505,41 @@
 ssage()).append(
-%22',%22
+SEPARATOR
 );%0A%09%09msg.append(
@@ -1586,36 +1586,41 @@
 tName()).append(
-%22',%22
+SEPARATOR
 );%0A%09%09msg.append(
@@ -1672,36 +1672,41 @@
 pCode()).append(
-%22',%22
+SEPARATOR
 );%0A%09%09if (event.g
@@ -1812,36 +1812,41 @@
 nCode()).append(
-%22',%22
+SEPARATOR
 );%0A%09%09%7D%0A%09%09if (eve
@@ -1957,36 +1957,41 @@
 dTime()).append(
-%22',%22
+SEPARATOR
 );%0A%09%09%7D%0A%09%09if (eve
@@ -2104,36 +2104,41 @@
 geAge()).append(
-%22',%22
+SEPARATOR
 );%0A%09%09%7D%0A%09%09if (eve
@@ -2205,36 +2205,41 @@
 etTag()).append(
-%22',%22
+SEPARATOR
 );%0A%09%09%7D%0A%09%09if (eve
@@ -2354,36 +2354,41 @@
 lator()).append(
-%22',%22
+SEPARATOR
 );%0A%09%09%7D%0A%09%09if (eve
@@ -2509,28 +2509,33 @@
 g()).append(
-%22',%22
+SEPARATOR
 );%0A%09%09%7D%0A%09%09msg
@@ -2598,23 +2598,68 @@
 .append(
-%22',%22);%0A
+SEPARATOR);%0A%09%09if (event.getParentItem() != null) %7B%0A%09
 %09%09msg.ap
@@ -2664,21 +2664,22 @@
 append(%22
-track
+parent
 -id='%22).
@@ -2687,24 +2687,40 @@
 ppend(event.
+getParentItem().
 getTrackingI
@@ -2735,55 +2735,24 @@
 end(
-%22',%22);%0A%09%09if (event.getParentItem() != null) %7B%0A%09
+SEPARATOR);%0A%09%09%7D%0A
 %09%09ms
@@ -2753,38 +2753,37 @@
 %7D%0A%09%09msg.append(%22
-parent
+track
 -id='%22).append(e
@@ -2787,32 +2787,16 @@
 d(event.
-getParentItem().
 getTrack
@@ -2817,20 +2817,16 @@
 d(%22'%22);%0A
-%09%09%7D%0A
 %09%09msg.ap

Improve SimpleFormatter output for readability