From df77288c997405206fd49e7fd91ac9d5d307b194 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Thu, 26 Sep 2024 13:58:32 -0500 Subject: [PATCH] Allow CLI implementations to override the default log base (#669) This change allows external (non-colcon) CLI implementations to specify a default for --log-base directory. --- colcon_core/command.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/colcon_core/command.py b/colcon_core/command.py index 92fc7b62..6e8faf6f 100644 --- a/colcon_core/command.py +++ b/colcon_core/command.py @@ -94,6 +94,7 @@ def register_command_exit_handler(handler): def main( *, command_name='colcon', argv=None, verb_group_name=None, environment_variable_group_name=None, default_verb=None, + default_log_base='log', ): """ Execute the main logic of the command. @@ -119,6 +120,8 @@ def main( for environment variables :param Type default_verb: The verb class type to invoke if no explicit verb was provided on the command line + :param str default_log_base: The default logging base path if the command + line argument isn't specified and the environment variable is not set :returns: The return code """ try: @@ -126,7 +129,7 @@ def main( command_name=command_name, argv=argv, verb_group_name=verb_group_name, environment_variable_group_name=environment_variable_group_name, - default_verb=default_verb) + default_verb=default_verb, default_log_base=default_log_base) except KeyboardInterrupt: return signal.SIGINT finally: @@ -138,7 +141,7 @@ def main( def _main( *, command_name, argv, verb_group_name, environment_variable_group_name, - default_verb + default_verb, default_log_base, ): # default log level, for searchability: COLCON_LOG_LEVEL colcon_logger.setLevel(logging.WARNING) @@ -204,7 +207,7 @@ def _main( set_default_log_path( base_path=args.log_base, env_var=f'{command_name}_LOG_PATH'.upper(), - subdirectory=subdirectory) + subdirectory=subdirectory, default=default_log_base) # add a file handler writing all levels if logging isn't disabled log_path = get_log_path()