Skip to content

Commit eed914a

Browse files
author
Yuki Nishiwaki
committed
Output traceback to log if msgpack raise exception
This patch change so that it can log traceback without abnormal termination, if msgpack raise exception. Fixed: fluent#49
1 parent 875bc72 commit eed914a

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

@@ -54,7 +55,13 @@ def emit(self, label, data):
5455
self.emit_with_time(label, cur_time, data)
5556

5657
def emit_with_time(self, label, timestamp, data):
57-
bytes_ = self._make_packet(label, timestamp, data)
58+
try:
59+
bytes_ = self._make_packet(label, timestamp, data)
60+
except Exception:
61+
bytes_ = self._make_packet(label, timestamp,
62+
{"level": "CRITICAL",
63+
"message": "Can't output to log",
64+
"traceback": traceback.format_exc()})
5865
self._send(bytes_)
5966

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

0 commit comments

Comments
 (0)