Skip to content

Instantly share code, notes, and snippets.

@nbessi
Created May 26, 2011 15:26
Show Gist options
  • Save nbessi/993356 to your computer and use it in GitHub Desktop.
Save nbessi/993356 to your computer and use it in GitHub Desktop.
Nice Logger helper from Florent really useful
import netsvc
logger = netsvc.Logger()
class Logger(object):
"""Provide an API similar to the standard 'logging' module."""
__slots__ = ('name',)
def __init__(self, name):
self.name = name
def log(self, level, msg, _log=logger.notifyChannel):
_log(self.name, level, msg)
def debug(self, msg):
self.log(netsvc.LOG_DEBUG, msg)
def info(self, msg):
self.log(netsvc.LOG_INFO, msg)
def warning(self, msg):
self.log(netsvc.LOG_WARNING, msg)
warn = warning
def error(self, msg):
self.log(netsvc.LOG_ERROR, msg)
def critical(self, msg):
self.log(netsvc.LOG_CRITICAL, msg)
fatal = critical
# Sample
Logger('Sorry but').error(_('S**t happens'))
@xrg
Copy link

xrg commented May 26, 2011

Why do you have to use that, anyway?
netsvc.Logger is deprecated in favour of pythonic logging.

@nbessi
Copy link
Author

nbessi commented May 27, 2011

You know there is still a lot of project running and developed under version 5 ...

@xrg
Copy link

xrg commented May 27, 2011

correct then..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment