Skip to content
Snippets Groups Projects
Commit c24e519e authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix bug related to log opening failures


If opening the log file fails, then we shouldn't attempt to use that
variable.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent c199dbae
No related branches found
No related tags found
No related merge requests found
......@@ -245,9 +245,18 @@ def SetupLogging(logfile, program, debug=0, stderr_logging=False,
# exception since otherwise we could run but without any logs at all
try:
if console_logging:
logfile_handler = _LogHandler(open(constants.DEV_CONSOLE, "a"), logfile)
logfile_handler = _LogHandler(open(constants.DEV_CONSOLE, "a"),
logfile)
else:
logfile_handler = _ReopenableLogHandler(logfile)
logfile_handler.setFormatter(formatter)
if debug:
logfile_handler.setLevel(logging.DEBUG)
else:
logfile_handler.setLevel(logging.INFO)
root_logger.addHandler(logfile_handler)
reopen_handlers.append(logfile_handler)
except EnvironmentError:
if stderr_logging or syslog == constants.SYSLOG_YES:
logging.exception("Failed to enable logging to file '%s'", logfile)
......@@ -255,13 +264,4 @@ def SetupLogging(logfile, program, debug=0, stderr_logging=False,
# we need to re-raise the exception
raise
logfile_handler.setFormatter(formatter)
if debug:
logfile_handler.setLevel(logging.DEBUG)
else:
logfile_handler.setLevel(logging.INFO)
root_logger.addHandler(logfile_handler)
reopen_handlers.append(logfile_handler)
return compat.partial(_ReopenLogFiles, reopen_handlers)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment