9
9
from logstash_async .formatter import LogstashFormatter
10
10
from logstash_async .utils import safe_log_via_print
11
11
from logstash_async .worker import LogProcessingWorker
12
- import logstash_async
13
12
from .transport import HttpTransport
14
13
15
14
@@ -28,8 +27,6 @@ class AsynchronousLogstashHandler(Handler):
28
27
the database. (Given in seconds. Default is None, and disables this feature)
29
28
"""
30
29
31
- _worker_thread = None
32
-
33
30
# ----------------------------------------------------------------------
34
31
# pylint: disable=too-many-arguments
35
32
def __init__ (self , host , port ,
@@ -43,6 +40,7 @@ def __init__(self, host, port,
43
40
self ._transport = transport
44
41
self ._event_ttl = event_ttl
45
42
self ._encoding = encoding
43
+ self ._worker_thread = None
46
44
self ._setup_transport (** kwargs )
47
45
48
46
# ----------------------------------------------------------------------
@@ -53,10 +51,9 @@ def emit(self, record):
53
51
self ._setup_transport ()
54
52
self ._start_worker_thread ()
55
53
56
- # basically same implementation as in logging.handlers.SocketHandler.emit()
57
54
try :
58
55
data = self ._format_record (record )
59
- AsynchronousLogstashHandler ._worker_thread .enqueue_event (data )
56
+ self ._worker_thread .enqueue_event (data )
60
57
except Exception :
61
58
self .handleError (record )
62
59
@@ -80,23 +77,18 @@ def _start_worker_thread(self):
80
77
if self ._worker_thread_is_running ():
81
78
return
82
79
83
- AsynchronousLogstashHandler ._worker_thread = LogProcessingWorker (
80
+ self ._worker_thread = LogProcessingWorker (
84
81
host = self ._host ,
85
82
port = self ._port ,
86
83
transport = self ._transport ,
87
84
ssl_enable = self ._ssl_enable ,
88
- cache = logstash_async . EVENT_CACHE ,
85
+ cache = {} ,
89
86
event_ttl = self ._event_ttl )
90
- AsynchronousLogstashHandler ._worker_thread .start ()
87
+ self ._worker_thread .start ()
91
88
92
89
# ----------------------------------------------------------------------
93
- @staticmethod
94
- def _worker_thread_is_running ():
95
- worker_thread = AsynchronousLogstashHandler ._worker_thread
96
- if worker_thread is not None and worker_thread .is_alive ():
97
- return True
98
-
99
- return False
90
+ def _worker_thread_is_running (self ):
91
+ return self ._worker_thread is not None and self ._worker_thread .is_alive ()
100
92
101
93
# ----------------------------------------------------------------------
102
94
def _format_record (self , record ):
@@ -132,15 +124,15 @@ def shutdown(self):
132
124
133
125
# ----------------------------------------------------------------------
134
126
def _trigger_worker_shutdown (self ):
135
- AsynchronousLogstashHandler ._worker_thread .shutdown ()
127
+ self ._worker_thread .shutdown ()
136
128
137
129
# ----------------------------------------------------------------------
138
130
def _wait_for_worker_thread (self ):
139
- AsynchronousLogstashHandler ._worker_thread .join ()
131
+ self ._worker_thread .join ()
140
132
141
133
# ----------------------------------------------------------------------
142
134
def _reset_worker_thread (self ):
143
- AsynchronousLogstashHandler ._worker_thread = None
135
+ self ._worker_thread = None
144
136
145
137
# ----------------------------------------------------------------------
146
138
def _close_transport (self ):
0 commit comments