Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_setup_logger_reconfiguration():
"""
Should be able to reconfigure without loosing custom handlers
"""
logzero.reset_default_logger()
temp = tempfile.NamedTemporaryFile()
temp2 = tempfile.NamedTemporaryFile()
try:
logzero.setup_default_logger(logfile=temp.name)
# Add a custom file handler
filehandler = logging.FileHandler(temp2.name)
filehandler.setLevel(logging.DEBUG)
filehandler.setFormatter(logzero.LogFormatter(color=False))
logzero.logger.addHandler(filehandler)
# First debug message goes to both files
logzero.logger.debug("debug1")
# Reconfigure logger to remove logfile
logzero.setup_default_logger()
logzero.logger.debug("debug2")
# Reconfigure logger to add logfile
logzero.setup_default_logger(logfile=temp.name)
logzero.logger.debug("debug3")
# Reconfigure logger to set minimum loglevel to INFO
logzero.setup_default_logger(logfile=temp.name, level=logging.INFO)
logzero.logger.debug("debug4")
logzero.logger.info("info1")
def _logger():
"""Add the multiprocessing module's logger.
:return: Returns a multiprocessing logger.
"""
multiprocess_handler = get_logger()
multiprocess_handler = logging.StreamHandler()
multiprocess_handler.setLevel(logging.ERROR)
multiprocess_handler.setFormatter(logzero.LogFormatter(color=True))
# Attach it to the logzero default logger
logzero.logger.addHandler(multiprocess_handler)
logger = logzero.logger
return logger