Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added custom formatter support #1

Closed
wants to merge 1 commit into from

1 participant

@macie-korte

The emitter code was not calling the format() method on the record before submitting it to Scribe which made it difficult to do custom formatting of log messages. I added a few lines of code to ensure any set formats are applied before logging. I followed the behavior of the StreamHandler in Python which both applies the format and adds a newline before logging. I did test this on my local machine and it worked fine for me.

@macie-korte macie-korte If formatting is set on this handler, it now applies that formatting …
…to the record before logging it to a Scribe server.

The altered behavior of the emit() function was modeled after the StreamHandler class in Python's logging module.
91fa2ba
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 4, 2011
  1. @macie-korte

    If formatting is set on this handler, it now applies that formatting …

    macie-korte authored
    …to the record before logging it to a Scribe server.
    
    The altered behavior of the emit() function was modeled after the StreamHandler class in Python's logging module.
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 2 deletions.
  1. +13 −2 ScribeHandler.py
View
15 ScribeHandler.py
@@ -88,6 +88,18 @@ def __setattr__(self, var, val):
def emit(self, record):
+ """
+ Emit a record.
+
+ If a formatter is specified, it is used to format the record.
+ The record is then logged to Scribe with a trailing newline.
+ """
+ # apply formatting to the record.
+ msg = self.format(record)
+ # for backwards-compatibility, do not add in a line break if it
+ # is already being manually added into each record.
+ if not msg.startswith('\n') or msg.endswith('\n'):
+ msg += '\n'
if (self.client is None) or (self.transport is None):
raise ScribeTransportError('No transport defined')
@@ -107,8 +119,7 @@ def emit(self, record):
'hostname' : socket.gethostname(),
}
- log_entry = scribe.LogEntry(category=category,
- message=record.getMessage())
+ log_entry = scribe.LogEntry(category=category, message=msg)
try:
self.transport.open()
Something went wrong with that request. Please try again.