Skip to content

Commit 2c3d1a4

Browse files
authored
Merge pull request #2918 from petridishdev/fix/logging-config
2 parents 1a4b710 + 4a699f3 commit 2c3d1a4

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

aries_cloudagent/config/default_multitenant_logging_config.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ args = (sys.stderr,)
2121
class = logging.handlers.TimedRotatingFileMultiProcessHandler
2222
level = DEBUG
2323
formatter = formatter
24-
args = ('test.log', 'd', 7, 1)
24+
args = ('agent.log', 'd', 7, 1)
2525

2626
[formatter_formatter]
2727
format = %(asctime)s %(wallet_id)s %(levelname)s %(pathname)s:%(lineno)d %(message)s

aries_cloudagent/config/logging.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,27 +163,42 @@ def configure(
163163
enabled
164164
"""
165165

166+
write_to_log_file = log_file is not None or log_file == ""
167+
166168
if multitenant:
169+
# The default logging config for multi-tenant mode specifies a log file
170+
# location if --log-file is specified on startup and a config file is not.
171+
# When all else fails, the default single-tenant config file is used.
172+
if not log_config_path:
173+
log_config_path = (
174+
cls.default_multitenant_config_path_ini
175+
if write_to_log_file
176+
else cls.default_config_path_ini
177+
)
178+
167179
cls._configure_multitenant_logging(
168-
log_config_path=log_config_path
169-
or DEFAULT_MULTITENANT_LOGGING_CONFIG_PATH_INI,
180+
log_config_path=log_config_path,
170181
log_level=log_level,
171182
log_file=log_file,
172183
)
173184
else:
185+
# The default config for single-tenant mode does not specify a log file
186+
# location. This is a check that requires a log file path to be provided if
187+
# --log-file is specified on startup and a config file is not.
188+
if not log_config_path and write_to_log_file and not log_file:
189+
raise ValueError(
190+
"log_file (--log-file) must be provided in single-tenant mode "
191+
"using the default config since a log file path is not set."
192+
)
193+
174194
cls._configure_logging(
175-
log_config_path=log_config_path or DEFAULT_LOGGING_CONFIG_PATH_INI,
195+
log_config_path=log_config_path or cls.default_config_path_ini,
176196
log_level=log_level,
177197
log_file=log_file,
178198
)
179199

180200
@classmethod
181201
def _configure_logging(cls, log_config_path, log_level, log_file):
182-
if log_file is not None and log_file == "":
183-
raise ValueError(
184-
"log_file (--log-file) must be provided in singletenant mode."
185-
)
186-
187202
# Setup log config and log file if provided
188203
cls._setup_log_config_file(log_config_path, log_file)
189204

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

200215
@classmethod
201216
def _configure_multitenant_logging(cls, log_config_path, log_level, log_file):
202-
# Unlike in singletenant mode, the defualt config for multitenant mode
203-
# specifies a default log_file if one is not explicitly provided
204-
# so we don't need the same check here
205-
206217
# Setup log config and log file if provided
207218
cls._setup_log_config_file(log_config_path, log_file)
208219

0 commit comments

Comments
 (0)