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

cat.inspiracio.util.Timber Maven / Gradle / Ivy

Go to download

Orange Servlet provides HTML templating with server-side Java. OrangeServlet is a servlet that is registered on *.html. It reads the html file at the right location according to URL. It renders the file as html, executing some scripting: * data-if="E" attributes for server-side conditional, * data-for="T x : E" attributes for server-side loops, * data-import="C" attributes for server-side class imports, * data-substitute="file.html" substitute an element with the processed contents of a file, * ${expressions} in element bodies and attribute values.

There is a newer version: 5.0.0
Show newest version
package cat.inspiracio.util;

import java.util.HashMap;
import java.util.Map;

public class Timber {

	private static ThreadLocal local=new ThreadLocal(){
		@Override protected Timber initialValue(){return new Timber();}
	};

	private Mapstarts=new HashMap();
	private StringBuilder events=new StringBuilder();
	
	// public --------------------------------
	
	public static void start(String key){
		Timber t=local.get();
		t.starts.put(key, System.currentTimeMillis());
	}
	
	public static void stop(String key){
		Timber t=local.get();
		Long start=t.starts.remove(key);//may be null
		if(start==null)
			return;//No call to start(key) since last string()
		long delta=System.currentTimeMillis()-start;
		t.events.append(key).append('=').append(delta).append("\n");
	}
	
	/** Can be "" but never null. */
	public static String string(){
		Timber t=local.get();
		String s=t.events.toString();
		t.events=new StringBuilder();
		t.starts.clear();
		return s;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy