[swarming] Add permanent log handler for swarming_bot_init.log
This is so we can pipe this log to cloud logging. The location of the temp file is inconsistent across OSes and it changes.
Bug: b/268122971
Change-Id: I4ed68800403ec7d187b7b92edbbbed93eb3c97b5
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/luci-py/+/4227440
Commit-Queue: Justin Luong <justinluong@google.com>
Reviewed-by: Vadim Shtayura <vadimsh@chromium.org>
NOKEYCHECK=True
GitOrigin-RevId: 451983ca6e266f5de1a2b0aa5c317d4486dccdac
diff --git a/utils/logging_utils.py b/utils/logging_utils.py
index fd928c6..879e03c 100644
--- a/utils/logging_utils.py
+++ b/utils/logging_utils.py
@@ -174,6 +174,20 @@
return log
+def new_rotating_file_handler(
+ filename,
+ utc_formatter=UTCFormatter(
+ '%(process)d %(asctime)s %(severity)s: %(message)s')):
+ file_path.ensure_tree(os.path.dirname(os.path.abspath(filename)))
+ rotating_file = NoInheritRotatingFileHandler(filename,
+ maxBytes=10 * 1024 * 1024,
+ backupCount=5,
+ encoding='utf-8')
+ rotating_file.setLevel(logging.DEBUG)
+ rotating_file.setFormatter(utc_formatter)
+ rotating_file.addFilter(SeverityFilter())
+ return rotating_file
+
def prepare_logging(filename, root=None):
"""Prepare logging for scripts.
@@ -204,15 +218,8 @@
# Setup up logging to a constant file so we can debug issues where
# the results aren't properly sent to the result URL.
if filename:
- file_path.ensure_tree(os.path.dirname(os.path.abspath(filename)))
try:
- rotating_file = NoInheritRotatingFileHandler(
- filename, maxBytes=10 * 1024 * 1024, backupCount=5,
- encoding='utf-8')
- rotating_file.setLevel(logging.DEBUG)
- rotating_file.setFormatter(utc_formatter)
- rotating_file.addFilter(SeverityFilter())
- logger.addHandler(rotating_file)
+ logger.addHandler(new_rotating_file_handler(filename, utc_formatter))
except Exception:
# May happen on cygwin. Do not crash.
logging.exception('Failed to open %s', filename)