All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.test4j.module.tracer.XmlFileTracerLogger Maven / Gradle / Ivy

package org.test4j.module.tracer;

import java.io.IOException;
import java.io.Writer;

import org.test4j.tools.commons.StringHelper;

@SuppressWarnings("rawtypes")
public class XmlFileTracerLogger extends TracerLogger {

	private StringBuilder buff = new StringBuilder();

	private int tabCount = 1;

	public void writerMethodInputInfo(Class claz, String method, Object[] values) {
		this.writeTab(1);
		buff.append(String.format("\n", claz.getName(), method));
		this.writeTab(1);
		buff.append(String.format("\n", values.length));
		for (int index = 1; index <= values.length; index++) {
			this.writeTab(0);
			buff.append("");
			buff.append("");
			buff.append("\n");
		}
		this.tabCount--;
		this.writeTab(0);
		buff.append("\n");
	}

	public void writerMethodException(Class claz, String method, Throwable exception) {
		this.writeTab(-1);
		buff.append("");
		} else {
			buff.append(exception.getClass().getName()).append(":").append(exception.getMessage());
		}
		buff.append("]]>\n");
		// end call
		this.writeTab(0);
		buff.append("\n");
	}

	public void writerMethodReturnValue(Class claz, String method, Object result) {
		this.writeTab(-1);
		buff.append("\n");
		// end call
		this.writeTab(0);
		buff.append("\n");
	}

	public void writerSqlStatement(String sql, Object result) {
		this.writeTab(0);
		buff.append("\n");
	}

	protected String getTracerContext() {
		return buff.toString();
	}

	public void close() {
		String log = this.getTracerContext();
		if (StringHelper.isBlankOrNull(log)) {
			return;
		}
		try {
			Writer writer = getWriter("xml");
			writer.write("\n");
			writer.write(log);
			writer.write("");
			writer.close();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	private void writeTab(int step) {
		for (int index = 0; index < tabCount; index++) {
			buff.append("    ");
		}
		this.tabCount = tabCount + step;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy