Skip to content

Commit

Permalink
Merge pull request #2 from alexander-akhmetov/master
Browse files Browse the repository at this point in the history
Disabled ensure_ascii in JsonOutput
  • Loading branch information
svetlyak40wt committed May 27, 2016
2 parents 7d04ad6 + 68d77e9 commit a421d57
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions twiggy_goodies/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import os
import calendar
import anyjson
import json
import datetime
import six
import socket
Expand All @@ -22,7 +22,7 @@ def __init__(self, filename=None, stream=None, source_host=None):
self.filename = filename

def serialize_msg(msg):
return anyjson.serialize(self.format(msg, source_host=source_host))
return json.dumps(self.format(msg, source_host=source_host), ensure_ascii=False)

super(JsonOutput, self).__init__(format=serialize_msg, close_atexit=True)

Expand All @@ -49,7 +49,7 @@ def format(self, msg, source_host=None):
@staticmethod
def get_log_entry(msg, timestamp, source_host, fields):
return {
'@message': msg.text,
'@message': force_str(msg.text),
'@timestamp': timestamp.isoformat(),
'@source_host': source_host,
'@fields': fields,
Expand All @@ -70,4 +70,4 @@ def _close(self):
os.close(self.fd)

def _write(self, msg):
os.write(self.fd, (msg + '\n').encode('utf-8'))
os.write(self.fd, force_str(msg + '\n'))
4 changes: 2 additions & 2 deletions twiggy_goodies/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@


def force_str(text, encoding='utf-8'):
if six.text_type(text):
if isinstance(text, six.binary_type):
return text
return text.decode(encoding)
return text.encode(encoding)


def get_log_level_str(level):
Expand Down

0 comments on commit a421d57

Please sign in to comment.