def _open(self): # # Call the standard handler, and then change the file ownership # to enbackup: # retval = logging.FileHandler._open(self) chown_enbackup(self.baseFilename) return retval
def __init__(self, name, logfile=None, debugfile=None): # # We support logging messages to up to two different files; # one for log messages, and one for debug. We add filters # to the handlers to ensure only messages of the desired # verbosity get sent to each target. # self.logger = logging.getLogger(name) self.logger.setLevel(logging.DEBUG) self.formatter = logging.Formatter(default_format) if not os.path.exists(default_log_dir): os.makedirs(default_log_dir) chown_enbackup(default_log_dir) # # Log messages go to the specified log file, if any # if logfile != None: self.logfile = default_log_dir + logfile self.handler = EnbackupFileHandler(self.logfile) self.handler.setFormatter(self.formatter) self.handler.setLevel(logging.INFO) self.logger.addHandler(self.handler) # # Debug and Log messages go to the specified debugfile, # or the default enbackup debugfile if none was provided. # if debugfile == None: debugfile = default_debugfile self.debugfile = default_log_dir + debugfile self.debughandler = EnbackupFileHandler(self.debugfile) self.debughandler.setFormatter(self.formatter) self.debughandler.setLevel(logging.DEBUG) self.logger.addHandler(self.debughandler) # # Add a handler for printing error messages to stderr. # Note these will also get recorded in the debug and log # files. # handler = logging.StreamHandler(sys.stderr) handler.setLevel(logging.ERROR) handler.setFormatter(logging.Formatter("%(message)s")) self.logger.addHandler(handler)