Last active
August 29, 2015 14:13
-
-
Save mrts/7e02b312be2d2e0c9e17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util; | |
import org.apache.log4j.Logger; | |
import org.springframework.util.StopWatch; | |
public class DebugLogStopwatch implements AutoCloseable { | |
Logger logger; | |
StopWatch stopwatch; | |
public DebugLogStopwatch(Logger log, String label) { | |
logger = log; | |
stopwatch = new StopWatch(label); | |
stopwatch.start(); | |
} | |
@Override | |
public void close() throws Exception { | |
stopwatch.stop(); | |
if (logger.isDebugEnabled()) { | |
logger.debug(stopwatch.prettyPrint()); | |
} | |
} | |
} | |
/* Usage: | |
try (DebugLogStopwatch sw = new DebugLogStopwatch(logger, "label")) { | |
... | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment