// not for multi threaded apps public static <T> T muteLogger(Closure<T> closure) { LOG.debug("turning logging off"); Level level = Logger.getRootLogger().getLevel(); Logger.getRootLogger().setLevel(Level.ERROR); T result = null; try { result = closure.call(); } finally { Logger.getRootLogger().setLevel(level); LOG.debug("turning logging on"); } return result; }
public static <T> Duration time(Closure<T> closure) { long starttime = System.currentTimeMillis(); closure.call(); return new Duration(TimeUnit.MILLISECONDS, System.currentTimeMillis() - starttime); }