From c71cf30948c230d30ee0d7cd9fe303fb79826e75 Mon Sep 17 00:00:00 2001 From: JGStew Date: Thu, 29 Aug 2024 16:15:44 -0400 Subject: [PATCH] tweak plugin utils for logging --- examples/export_all_sites.py | 6 +++++- src/besapi/plugin_utilities.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/export_all_sites.py b/examples/export_all_sites.py index cec444b..b80774f 100644 --- a/examples/export_all_sites.py +++ b/examples/export_all_sites.py @@ -98,7 +98,11 @@ def main(): # get folder the script was invoked from: invoke_folder = get_invoke_folder() - log_file_path = invoke_folder + get_invoke_file_name() + ".log" + log_file_path = os.path.join( + get_invoke_folder(verbose), get_invoke_file_name(verbose) + ".log" + ) + + print(log_file_path) besapi.plugin_utilities.setup_plugin_logging(log_file_path) diff --git a/src/besapi/plugin_utilities.py b/src/besapi/plugin_utilities.py index 938531d..89bfb01 100644 --- a/src/besapi/plugin_utilities.py +++ b/src/besapi/plugin_utilities.py @@ -11,6 +11,7 @@ import besapi +# NOTE: This does not work as expected when run from plugin_utilities def get_invoke_folder(verbose=0): """Get the folder the script was invoked from""" # using logging here won't actually log it to the file: @@ -30,6 +31,7 @@ def get_invoke_folder(verbose=0): return invoke_folder +# NOTE: This does not work as expected when run from plugin_utilities def get_invoke_file_name(verbose=0): """Get the filename the script was invoked from""" # using logging here won't actually log it to the file: @@ -98,7 +100,7 @@ def setup_plugin_logging(log_file_path="", verbose=0, console=True): log_level = logging.WARNING if verbose: log_level = logging.INFO - print("INFO: Log File Path: %s", log_file_path) + print("INFO: Log File Path:", log_file_path) if verbose > 1: log_level = logging.DEBUG @@ -111,6 +113,7 @@ def setup_plugin_logging(log_file_path="", verbose=0, console=True): # log output to console if arg provided: if console: handlers.append(logging.StreamHandler()) + print("INFO: also logging to console") # setup logging: logging.basicConfig( @@ -118,6 +121,7 @@ def setup_plugin_logging(log_file_path="", verbose=0, console=True): level=log_level, format="%(asctime)s %(levelname)s:%(message)s", handlers=handlers, + force=True, )