Skip to content

Commit

Permalink
fix for issue #87 by checking sys.stdout.encoding for None and fallin…
Browse files Browse the repository at this point in the history
…g back to utf-8
  • Loading branch information
GitMirar committed Nov 16, 2017
1 parent 1d97792 commit d827217
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/lokilogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,17 @@ def log(self, mes_type, message):
self.log_to_remotesys(message, mes_type)

def log_to_stdout(self, message, mes_type):
# check tty encoding
encoding = ""
if sys.stdout.encoding is not None:
encoding = sys.stdout.encoding
else:
# fallback on utf-8
encoding = "utf-8"

# Prepare Message
codecs.register(lambda message: codecs.lookup('utf-8') if message == 'cp65001' else None)
message = message.encode(sys.stdout.encoding, errors='replace')
message = message.encode(encoding, errors='replace')

if self.csv:
print ("{0},{1},{2},{3}".format(getSyslogTimestamp(),self.hostname,mes_type,message))
Expand Down

0 comments on commit d827217

Please sign in to comment.