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

fix: fixes a regression that requires a log file in multi-tenant mode #2918

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ args = (sys.stderr,)
class = logging.handlers.TimedRotatingFileMultiProcessHandler
level = DEBUG
formatter = formatter
args = ('test.log', 'd', 7, 1)
args = ('agent.log', 'd', 7, 1)

[formatter_formatter]
format = %(asctime)s %(wallet_id)s %(levelname)s %(pathname)s:%(lineno)d %(message)s
Expand Down
35 changes: 23 additions & 12 deletions aries_cloudagent/config/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,27 +163,42 @@ def configure(
enabled
"""

write_to_log_file = log_file is not None or log_file == ""

if multitenant:
# The default logging config for multi-tenant mode specifies a log file
# location if --log-file is specified on startup and a config file is not.
# When all else fails, the default single-tenant config file is used.
if not log_config_path:
log_config_path = (
cls.default_multitenant_config_path_ini
if write_to_log_file
else cls.default_config_path_ini
)

cls._configure_multitenant_logging(
log_config_path=log_config_path
or DEFAULT_MULTITENANT_LOGGING_CONFIG_PATH_INI,
log_config_path=log_config_path,
log_level=log_level,
log_file=log_file,
)
else:
# The default config for single-tenant mode does not specify a log file
# location. This is a check that requires a log file path to be provided if
# --log-file is specified on startup and a config file is not.
if not log_config_path and write_to_log_file and not log_file:
raise ValueError(
"log_file (--log-file) must be provided in single-tenant mode "
"using the default config since a log file path is not set."
)

cls._configure_logging(
log_config_path=log_config_path or DEFAULT_LOGGING_CONFIG_PATH_INI,
log_config_path=log_config_path or cls.default_config_path_ini,
log_level=log_level,
log_file=log_file,
)

@classmethod
def _configure_logging(cls, log_config_path, log_level, log_file):
if log_file is not None and log_file == "":
raise ValueError(
"log_file (--log-file) must be provided in singletenant mode."
)

# Setup log config and log file if provided
cls._setup_log_config_file(log_config_path, log_file)

Expand All @@ -199,10 +214,6 @@ def _configure_logging(cls, log_config_path, log_level, log_file):

@classmethod
def _configure_multitenant_logging(cls, log_config_path, log_level, log_file):
# Unlike in singletenant mode, the defualt config for multitenant mode
# specifies a default log_file if one is not explicitly provided
# so we don't need the same check here

# Setup log config and log file if provided
cls._setup_log_config_file(log_config_path, log_file)

Expand Down