Skip to content

Commit 4974723

Browse files
committed
Merge pull request fluent#53 from ukinau/Fix_49_problem_with_exception_logging
Output traceback to log if msgpack raise exception
2 parents 2a62230 + eed914a commit 4974723

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fluent/sender.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import socket
55
import threading
66
import time
7+
import traceback
78

89
import msgpack
910

@@ -59,7 +60,13 @@ def emit(self, label, data):
5960
self.emit_with_time(label, cur_time, data)
6061

6162
def emit_with_time(self, label, timestamp, data):
62-
bytes_ = self._make_packet(label, timestamp, data)
63+
try:
64+
bytes_ = self._make_packet(label, timestamp, data)
65+
except Exception:
66+
bytes_ = self._make_packet(label, timestamp,
67+
{"level": "CRITICAL",
68+
"message": "Can't output to log",
69+
"traceback": traceback.format_exc()})
6370
self._send(bytes_)
6471

6572
def _make_packet(self, label, timestamp, data):

0 commit comments

Comments
 (0)