From 6d42de0f0333b6434d49780ad96a73dfd5ae8425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Sat, 8 Aug 2020 04:09:03 +0200 Subject: [PATCH] Extract default log filenames as a configuration constants sq put dfe --- nucypher/config/constants.py | 2 ++ nucypher/utilities/logging.py | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/nucypher/config/constants.py b/nucypher/config/constants.py index 06ac67fbf..ace1b3c59 100644 --- a/nucypher/config/constants.py +++ b/nucypher/config/constants.py @@ -46,6 +46,8 @@ CONTRACT_ROOT = SOL_PACKAGE / 'source' / 'contracts' APP_DIR = AppDirs(nucypher.__title__, nucypher.__author__) DEFAULT_CONFIG_ROOT = os.getenv('NUCYPHER_CONFIG_ROOT', default=APP_DIR.user_data_dir) USER_LOG_DIR = os.getenv('NUCYPHER_USER_LOG_DIR', default=APP_DIR.user_log_dir) +DEFAULT_LOG_FILENAME = "nucypher.log" +DEFAULT_JSON_LOG_FILENAME = "nucypher.json" # Static Seednodes diff --git a/nucypher/utilities/logging.py b/nucypher/utilities/logging.py index 244328c52..e4d866f94 100644 --- a/nucypher/utilities/logging.py +++ b/nucypher/utilities/logging.py @@ -21,17 +21,22 @@ from contextlib import contextmanager import pathlib from twisted.logger import ( FileLogObserver, - LogLevel, formatEvent, formatEventAsClassicLogText, globalLogPublisher, - jsonFileLogObserver + jsonFileLogObserver, + LogLevel, ) from twisted.logger import Logger as TwistedLogger from twisted.python.logfile import LogFile import nucypher -from nucypher.config.constants import NUCYPHER_SENTRY_ENDPOINT, USER_LOG_DIR +from nucypher.config.constants import ( + DEFAULT_JSON_LOG_FILENAME, + DEFAULT_LOG_FILENAME, + NUCYPHER_SENTRY_ENDPOINT, + USER_LOG_DIR, +) ONE_MEGABYTE = 1_048_576 MAXIMUM_LOG_SIZE = ONE_MEGABYTE * 10 @@ -171,14 +176,14 @@ def _ensure_dir_exists(path): pathlib.Path(path).mkdir(parents=True, exist_ok=True) -def get_json_file_observer(name="nucypher.json", path=USER_LOG_DIR): +def get_json_file_observer(name=DEFAULT_JSON_LOG_FILENAME, path=USER_LOG_DIR): _ensure_dir_exists(path) logfile = LogFile(name=name, directory=path, rotateLength=MAXIMUM_LOG_SIZE, maxRotatedFiles=MAX_LOG_FILES) observer = jsonFileLogObserver(outFile=logfile) return observer -def get_text_file_observer(name="nucypher.log", path=USER_LOG_DIR): +def get_text_file_observer(name=DEFAULT_LOG_FILENAME, path=USER_LOG_DIR): _ensure_dir_exists(path) logfile = LogFile(name=name, directory=path, rotateLength=MAXIMUM_LOG_SIZE, maxRotatedFiles=MAX_LOG_FILES) observer = FileLogObserver(formatEvent=formatEventAsClassicLogText, outFile=logfile)