/
githubmirror
/
the-algorithm
Обзор
Документация
Войти
/
githubmirror
/
the-algorithm
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/java/com/twitter/search/earlybird/util/ActionLogger.java
49 строк
1 KB
twitter-team
Twitter Recommendation Algorithm
01 апр 2023, 01:36
01 апр 2023, 01:36
ef4c5eb
Код
Авторство
О чём код?
package com.twitter.search.earlybird.util; import java.util.concurrent.Callable; import com.google.common.base.Stopwatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public final class ActionLogger { private static final Logger LOG = LoggerFactory.getLogger(ActionLogger.class); private ActionLogger() { } /** * Run a function, logging a message at the start and end, and the time it took. */ public static <T> T call(String message, Callable<T> fn) throws Exception { LOG.info("Action starting: '{}'.", message); Stopwatch stopwatch = Stopwatch.createStarted(); try { return fn.call(); } catch (Throwable e) { LOG.error("Action failed: '{}'.", message, e); throw e; } finally { LOG.info("Action finished in {} '{}'.", stopwatch, message); } } /** * Run a function, logging a message at the start and end, and the time it took. */ public static void run(String message, CheckedRunnable fn) throws Exception { call(message, () -> { fn.run(); return null; }); } @FunctionalInterface public interface CheckedRunnable { /** * A nullary function that throws checked exceptions. */ void run() throws Exception; } }