Skip to content

Instantly share code, notes, and snippets.

@jion
Created May 25, 2018 16:22
Show Gist options
  • Save jion/a1df345a7920b3f4d6ac819e171297bd to your computer and use it in GitHub Desktop.
Save jion/a1df345a7920b3f4d6ac819e171297bd to your computer and use it in GitHub Desktop.
Allows to redirect all the messages on a specific logger to another specified logger
import logging
class RedirectLoggingHandler(logging.Handler):
def __init__(self, dest_logger):
logging.Handler.__init__(self)
self.dest_logger = dest_logger
def emit(self, record):
try:
record.name = self.dest_logger.name
self.dest_logger.handle(record)
except:
self.handleError(record)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment