From 4e2ce168ca6600fa8e203e37f783739fc936abbf Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Sun, 24 Dec 2023 17:18:15 -0800 Subject: [PATCH] Allow macOS logging addition to be copied to clipboard --- docs_src/usersguide/monitoring.md | 4 ++-- src/weeutil/startup.py | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docs_src/usersguide/monitoring.md b/docs_src/usersguide/monitoring.md index 7684a6f2..b5d27ac5 100644 --- a/docs_src/usersguide/monitoring.md +++ b/docs_src/usersguide/monitoring.md @@ -105,7 +105,7 @@ that work with macOS 12.x or later are standalone handlers that log to files. Fortunately, there is a simple workaround. Put this at the bottom of your `weewx.conf` configuration file: -``` +```{.ini .copy} [Logging] [[root]] @@ -117,7 +117,7 @@ Fortunately, there is a simple workaround. Put this at the bottom of your level = DEBUG formatter = verbose class = logging.handlers.TimedRotatingFileHandler - # File to log to: + # File to log to, relative to WEEWX_ROOT: filename = log/{process_name}.log # When to rotate: when = midnight diff --git a/src/weeutil/startup.py b/src/weeutil/startup.py index 9f56a5b3..c17a924b 100644 --- a/src/weeutil/startup.py +++ b/src/weeutil/startup.py @@ -14,14 +14,6 @@ import weewx from weeutil.weeutil import to_int -def add_user_path(config_dict): - """add the path to the parent of the user directory to PYTHONPATH.""" - root_dict = extract_roots(config_dict) - lib_dir = os.path.abspath(os.path.join(root_dict['USER_DIR'], '..')) - sys.path.append(lib_dir) - return lib_dir - - def extract_roots(config_dict): """Get the location of the various root directories used by weewx. The extracted paths are *absolute* paths. That is, they are no longer relative to WEEWX_ROOT. @@ -51,7 +43,15 @@ def extract_roots(config_dict): def initialize(config_dict, log_label): - """Set debug, set up the logger, and add the user path""" + """Set debug, set up the logger, and add the user path + + Args: + config_dict(dict): The configuration dictionary + log_label(str): A label to be used in the log for this process + + Returns: + tuple[str,str]: A tuple containing (WEEWX_ROOT, USER_ROOT) + """ # Set weewx.debug as necessary: weewx.debug = to_int(config_dict.get('debug', 0)) @@ -59,8 +59,11 @@ def initialize(config_dict, log_label): # Customize the logging with user settings. weeutil.logger.setup(log_label, config_dict) + root_dict = extract_roots(config_dict) + # Add the 'user' package to PYTHONPATH - user_dir = add_user_path(config_dict) + user_dir = os.path.abspath(os.path.join(root_dict['USER_DIR'], '..')) + sys.path.append(user_dir) # Now we can import user.extensions try: @@ -69,4 +72,4 @@ def initialize(config_dict, log_label): log = logging.getLogger(__name__) log.error("Cannot load user extensions: %s", e) - return user_dir \ No newline at end of file + return config_dict['WEEWX_ROOT'], user_dir