Created
May 26, 2011 15:26
-
-
Save nbessi/993356 to your computer and use it in GitHub Desktop.
Nice Logger helper from Florent really useful
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 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')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
correct then..