class Logger(object): def __init__(self): self.init('.', os.path.split(sys.argv[0])[-1], True, True) # path, name, debug, print_to_console = '.', os.path.split(sys.argv[0])[-1], True, True def init(self, path, name, debug=False, print_to_console=False): self._debug = debug self._print_to_console = print_to_console self._log = DiaryRollingFileLogger(path, name) self._errlog = DiaryRollingFileLogger(path, '%s.error' % name) self._debuglog = FileLogger(path, '%s.debug' % name) if print_to_console: self._debuglog.enable_console(True) def msg(self, format, *args): self._log.log(format, *args) if self._debug: self._debuglog.log(u'[INFO]%s' % format, *args) def error(self, format, *args, **kwargs): self._errlog.error(format, *args, **kwargs) if self._debug: self._debuglog.error(u'[ERROR]%s' % format, *args, **kwargs) def debug(self, format, *args, **kwargs): if self._debug: self._debuglog.error(u'[DEBUG]%s' % format, *args, **kwargs)
def init(self, path, name, debug=False, print_to_console=False): self._debug = debug self._print_to_console = print_to_console self._log = DiaryRollingFileLogger(path, name) self._errlog = DiaryRollingFileLogger(path, '%s.error' % name) self._debuglog = FileLogger(path, '%s.debug' % name) if print_to_console: self._debuglog.enable_console(True)