From e1226f14e99eb15abf7813957a12ee4532d6f991 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 29 Mar 2020 13:20:13 +0000 Subject: clang-format.py: fix timestamps in logs --- tools/clang-format.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/clang-format.py b/tools/clang-format.py index 65321d2..2f64a5e 100755 --- a/tools/clang-format.py +++ b/tools/clang-format.py @@ -13,6 +13,7 @@ formatting the files in-place. ''' import argparse +from contextlib import contextmanager import difflib import logging import os.path @@ -20,10 +21,17 @@ import subprocess import sys +@contextmanager def _setup_logging(): logging.basicConfig( format='%(asctime)s | %(levelname)s | %(message)s', + datefmt='%Y-%m-%d %H:%M:%S', level=logging.INFO) + try: + yield + except Exception as e: + logging.exception(e) + raise def _run_executable(cmd_line): @@ -132,13 +140,9 @@ def _parse_args(argv=None): def main(argv=None): - _setup_logging() - try: + with _setup_logging(): args = _parse_args(argv) _process_cpp_files(args) - except Exception as e: - logging.exception(e) - raise if __name__ == '__main__': -- cgit v1.2.3