import syslog from import settings class SysLogging: def __init__(self, facility, prefix=None): self.facility = facility if prefix: syslog.openlog(prefix) def _logit(self, priority, message): syslog.syslog(self.facility | priority, '%s' % (message)) def debug(self, message): self._logit(syslog.LOG_DEBUG, message) def info(self, message): self._logit(syslog.LOG_INFO, message) def notice(self, message): self._logit(syslog.LOG_NOTICE, message) def warning(self, message): self._logit(syslog.LOG_WARNING, message) def error(self, message): self._logit(syslog.LOG_ERR, message) def crit(self, message): self._logit(syslog.LOG_CRIT, message) def alert(self, message): self._logit(syslog.LOG_ALERT, message) def emerg(self, message): self._logit(syslog.LOG_EMERG, message) def syslogging(func): def caller(*args, **kwargs): if 'logger' not in kwargs: kwargs['logger'] = SysLogging(settings.SYSLOG_FACILITY, func.__name__) return func(*args, **kwargs) return caller @syslogging def test_func(arg1, arg2=None, logger=None): logger.info('%s %s' % (arg1, arg2)) if __name__ == '__main__': test_func(1, 'two')