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

io.lsn.spring.utilities.stopwatch.StopwatchLog Maven / Gradle / Ivy

Go to download

Logisfera Nova Commons holds a bunch of useful helpers such as validators, conditional register process, soap logging handler

There is a newer version: 2.2.0
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy