8000 Merge branch 'moriyoshi/usable-logger-handler' into private-release · moriyoshi/fluent-logger-python@a6a3f89 · GitHub
[go: up one dir, main page]

Skip to content

Commit a6a3f89

Browse files
committed
Merge branch 'moriyoshi/usable-logger-handler' into private-release
2 parents 3c91be9 + 1c51fe2 commit a6a3f89

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This library is distributed as 'fluent-logger' python package. Please execute th
1919

2020
## Configuration
2121

22-
Fluent daemon must be lauched with the following configuration:
22+
Fluentd daemon must be lauched with the following configuration:
2323

2424
<source>
2525
type tcp
@@ -36,7 +36,7 @@ Fluent daemon must be lauched with the following configuration:
3636

3737
First, you need to call logger.setup() to create global logger instance. This call needs to be called only once, at the beggining of the application for example.
3838

39-
By default, the logger assumes fluent daemon is launched locally. You can also specify remote logger by passing the options.
39+
By default, the logger assumes fluentd daemon is launched locally. You can also specify remote logger by passing the options.
4040

4141
from fluent import sender
4242

fluent/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _decode(self, value):
6464
if value is None:
6565
return None
6666
elif isinstance(value, str):
67-
return unicode(value, self.encoding)
67+
return unicode(value, self.encoding, errors='replace')
6868
elif isinstance(value, unicode):
6969
return value
7070
else:

tests/test_decode.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding:utf-8 -*-
2+
3+
import unittest
4+
5+
class TestHandler(unittest.TestCase):
6+
7+
def _getTarget(self):
8+
from fluent.handler import FluentHandler
9+
return FluentHandler
10+
11+
12+
def _makeOne(self, *args, **kwargs):
13+
return self._getTarget()(*args, **kwargs)
14+
15+
16+
def test_decode_none(self):
17+
h = self._makeOne('app.follow')
18+
result = h._decode(None)
19+
self.assertIsNone(result)
20+
21+
def test_decode_str(self):
22+
h = self._makeOne('app.follow')
23+
result = h._decode("あいうえお")
24+
self.assertTrue(isinstance(result, unicode), type(result).__name__)
25+
self.assertEqual(result, u"あいうえお")
26+
27+
def test_decode_str2(self):
28+
h = self._makeOne('app.follow')
29+
result = h._decode(u"あいうえお".encode('Shift_JIS'))
30+
self.assertTrue(isinstance(result, unicode), type(result).__name__)
31+
self.assertEqual(result, u"\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd") # replaced
32+
33+
def test_decode_unicode(self):
34+
h = self._makeOne('app.follow')
35+
result = h._decode(u"あいうえお")
36+
self.assertTrue(isinstance(result, unicode), type(result).__name__)
37+
self.assertEqual(result, u"あいうえお")
38+
39+
def test_decode_obj(self):
40+
h = self._makeOne('app.follow')
41+
marker = object()
42+
result = h._decode(marker)
43+
self.assertTrue(isinstance(result, unicode), type(result).__name__)
44+
45+
self.assertEqual(result, str(marker))

0 commit comments

Comments
 (0)
0