Skip to content

Commit

Permalink
enhance the AggregateEmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud committed May 13, 2016
1 parent 2b9476a commit 7b56560
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 11 additions & 2 deletions lithoxyl/emitters.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ def check_encoding_settings(encoding, errors):

class AggregateEmitter(object):
def __init__(self):
self.entries = []
self.items = []

def get_entries(self):
return [entry for record, entry in self.items]

def get_entry(self, idx):
return self.items[idx][1]

def clear(self):
self.items[:] = []

def emit_entry(self, record, entry):
self.entries.append((record, entry))
self.items.append((record, entry))

on_begin = on_warn = on_end = on_comment = emit_entry

Expand Down
8 changes: 4 additions & 4 deletions lithoxyl/tests/test_sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ def test_sensible_basic():
print

log.debug('greet').success('hey')
assert aggr_emtr.entries[-1][1][0] == 's'
assert aggr_emtr.get_entry(-1).startswith('s')

with log.debug('greet') as t:
t.success('hello')
t.warn("everything ok?")

assert aggr_emtr.entries[-1][1][0] == 'S'
assert aggr_emtr.get_entry(-1).startswith('S')

with log.debug('greet') as t:
t.failure('bye')
assert aggr_emtr.entries[-1][1][0] == 'F'
assert aggr_emtr.get_entry(-1).startswith('F')

try:
with log.debug('greet') as t:
raise ZeroDivisionError('narwhalbaconderp')
except Exception:
pass

assert aggr_emtr.entries[-1][1][0] == 'E'
assert aggr_emtr.get_entry(-1).startswith('E')


def test_bad_encoding():
Expand Down

0 comments on commit 7b56560

Please sign in to comment.