Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CLI implementations to override the default log base #669

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions colcon_core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -119,14 +120,16 @@ 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:
return _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:
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
Loading