Permalink
Browse files

offer the prepare callback for non-exception messages. this change is…

… backwards-incompatible. change 'prepareException' to 'prepareMessage' to support this change.
  • Loading branch information...
1 parent 7554f75 commit 1c85a2f11ea7321654088f6341fbe32de7a7d07b Daniel Gross committed Nov 10, 2012
Showing with 8 additions and 5 deletions.
  1. +8 −5 python/logging/greplin/gec/logHandler.py
@@ -28,12 +28,12 @@ class GecHandler(logging.Handler):
"""Log observer that writes exceptions to json files to be picked up by upload.py."""
- def __init__(self, path, project, environment, serverName, prepareException=None):
+ def __init__(self, path, project, environment, serverName, prepareMessage=None):
self.__path = path
self.__project = project
self.__environment = environment
self.__serverName = serverName
- self.__prepareException = prepareException
+ self.__prepareMessage = prepareMessage
logging.Handler.__init__(self)
@@ -68,11 +68,14 @@ def formatLogMessage(self, item):
except TypeError:
itemMessage = 'Error formatting message'
- return {
+ log = {
'type': "%s message" % item.levelname,
'message': itemMessage,
'backtrace': "%s:%d at %s" % (item.module, item.lineno, item.pathname)
}
+ if self.__prepareMessage:
+ return self.__prepareMessage(log)
+ return log
def formatException(self, item):
@@ -83,8 +86,8 @@ def formatException(self, item):
'logMessage': getattr(item, 'message', None) or getattr(item, 'msg', None),
'backtrace': item.exc_text
}
- if self.__prepareException:
- return self.__prepareException(exception)
+ if self.__prepareMessage:
+ return self.__prepareMessage(exception)
return exception

0 comments on commit 1c85a2f

Please sign in to comment.