Created
March 8, 2011 23:24
-
-
Save tbartelmess/861353 to your computer and use it in GitHub Desktop.
Syslogger for django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import syslog | |
from #YOUAPP# 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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment