Skip to content

Commit

Permalink
tweak a emitter, pop a TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud committed Mar 13, 2016
1 parent 31fb366 commit c52fbfb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lithoxyl/emitters.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def emit_entry(self, record, entry):
on_begin = on_warn = on_complete = on_comment = emit_entry


# TODO: rename StreamLineEmitter
class StreamEmitter(object):
def __init__(self, stream, encoding=None, **kwargs):
if stream == 'stdout':
Expand All @@ -67,7 +66,9 @@ def __init__(self, stream, encoding=None, **kwargs):

check_encoding_settings(encoding, errors) # raises on error

self.newline = kwargs.pop('newline', None) or os.linesep
self.sep = kwargs.pop('sep', None)
if self.sep is None:
self.sep = os.linesep
self.errors = errors
self.encoding = encoding

Expand All @@ -82,8 +83,8 @@ def emit_entry(self, record, entry):
raise
try:
self.stream.write(entry)
if self.newline:
self.stream.write(self.newline)
if self.sep:
self.stream.write(self.sep)
self.flush()
except Exception as e:
note('stream_emit', 'got %r on %r.emit_entry()', e, self)
Expand All @@ -107,7 +108,7 @@ class FileEmitter(StreamEmitter):
def __init__(self, filepath, encoding=None, **kwargs):
self.filepath = os.path.abspath(filepath)
self.encoding = encoding
self.mode = 'a' # always 'a'?
self.mode = 'a'
stream = open(self.filepath, self.mode)
super(FileEmitter, self).__init__(stream, self.encoding, **kwargs)

Expand Down

0 comments on commit c52fbfb

Please sign in to comment.