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

Switch log.py's own logger to independant logger #861

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 21 additions & 4 deletions python/tank/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def my_method():
from logging.handlers import RotatingFileHandler
import os
import sys
import tempfile
import time
import weakref
import uuid
Expand Down Expand Up @@ -304,7 +305,7 @@ def doRollover(self):

try:
os.rename(self.baseFilename, temp_backup_name)
except:
except OSError:
# It failed, so we'll simply append from now on.
log.debug(
"Cannot rotate log file '%s'. Logging will continue to this file, "
Expand All @@ -319,7 +320,7 @@ def doRollover(self):
# so doRollover can do its work.
try:
os.rename(temp_backup_name, self.baseFilename)
except:
except OSError:
# For some reason we couldn't move the backup in its place.
log.debug(
"Unexpected issue while rotating log file '%s'. Logging will continue to this file, "
Expand All @@ -344,7 +345,7 @@ def doRollover(self):
# disable rollover and append to the current log.
try:
RotatingFileHandler.doRollover(self)
except:
except Exception:
# Something probably failed trying to rollover the backups,
# since the code above proved that in theory the main log file
# should be renamable. In any case, we didn't succeed in renaming,
Expand Down Expand Up @@ -824,7 +825,23 @@ def initialize_base_file_handler_from_path(self, log_file):


# the logger for logging messages from this file :)
log = LogManager.get_logger(__name__)
# using python default's logger just in case the LogManager fails and we need to debug it, logging to a tempfile
log = logging.getLogger("fallback")
log.setLevel(logging.INFO)
fallback_log_filepath = os.path.join(
tempfile.gettempdir(),
"{}.fallback.log".format(constants.ROOT_LOGGER_NAME)
)
fh = logging.FileHandler(fallback_log_filepath)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
log.addHandler(fh)
log.info("fallback default logger setup")

if os.environ.get(constants.DEBUG_LOGGING_ENV_VAR, False):
log.setLevel(logging.DEBUG)
log.debug("debug mode on")


# initialize toolkit logging
#
Expand Down