io.lsn.spring.utilities.stopwatch.StopwatchLog Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utilities Show documentation
Show all versions of utilities Show documentation
Logisfera Nova Commons holds a bunch of useful helpers such as validators, conditional register
process, soap logging handler
package io.lsn.spring.utilities.stopwatch;
import org.apache.log4j.Logger;
import java.util.Date;
/**
* @author Patryk Szlagowski
*/
public class StopwatchLog {
private final static Logger logger = Logger.getLogger(StopwatchLog.class);
private Log last;
private String section;
public StopwatchLog(String section) {
this.section = section;
}
/**
* log roznicy miedzy dwoma markerami
*
* @param name
*/
public void log(String name) {
if (last == null) {
last = new Log(name, new Date());
return;
}
Log current = new Log(name, new Date());
logger.info("["+section+"] stopwatch diff "+last.getName()+":"+current.getName()+"="+last.diff(current)+"ms - timestamp:"+current.getDate().getTime());
last = current;
}
/**
* start sesji - czyscimy poprzednia instancje na wszelki wypadek
*/
public void start() {
last = null;
}
/**
* koniec sesji
*/
public void end() {
last = null;
}
}