99from logstash_async .formatter import LogstashFormatter
1010from logstash_async .utils import safe_log_via_print
1111from logstash_async .worker import LogProcessingWorker
12- import logstash_async
1312from .transport import HttpTransport
1413
1514
@@ -28,8 +27,6 @@ class AsynchronousLogstashHandler(Handler):
2827 the database. (Given in seconds. Default is None, and disables this feature)
2928 """
3029
31- _worker_thread = None
32-
3330 # ----------------------------------------------------------------------
3431 # pylint: disable=too-many-arguments
3532 def __init__ (self , host , port ,
@@ -43,6 +40,7 @@ def __init__(self, host, port,
4340 self ._transport = transport
4441 self ._event_ttl = event_ttl
4542 self ._encoding = encoding
43+ self ._worker_thread = None
4644 self ._setup_transport (** kwargs )
4745
4846 # ----------------------------------------------------------------------
@@ -53,10 +51,9 @@ def emit(self, record):
5351 self ._setup_transport ()
5452 self ._start_worker_thread ()
5553
56- # basically same implementation as in logging.handlers.SocketHandler.emit()
5754 try :
5855 data = self ._format_record (record )
59- AsynchronousLogstashHandler ._worker_thread .enqueue_event (data )
56+ self ._worker_thread .enqueue_event (data )
6057 except Exception :
6158 self .handleError (record )
6259
@@ -80,23 +77,18 @@ def _start_worker_thread(self):
8077 if self ._worker_thread_is_running ():
8178 return
8279
83- AsynchronousLogstashHandler ._worker_thread = LogProcessingWorker (
80+ self ._worker_thread = LogProcessingWorker (
8481 host = self ._host ,
8582 port = self ._port ,
8683 transport = self ._transport ,
8784 ssl_enable = self ._ssl_enable ,
88- cache = logstash_async . EVENT_CACHE ,
85+ cache = {} ,
8986 event_ttl = self ._event_ttl )
90- AsynchronousLogstashHandler ._worker_thread .start ()
87+ self ._worker_thread .start ()
9188
9289 # ----------------------------------------------------------------------
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 ()
10092
10193 # ----------------------------------------------------------------------
10294 def _format_record (self , record ):
@@ -132,15 +124,15 @@ def shutdown(self):
132124
133125 # ----------------------------------------------------------------------
134126 def _trigger_worker_shutdown (self ):
135- AsynchronousLogstashHandler ._worker_thread .shutdown ()
127+ self ._worker_thread .shutdown ()
136128
137129 # ----------------------------------------------------------------------
138130 def _wait_for_worker_thread (self ):
139- AsynchronousLogstashHandler ._worker_thread .join ()
131+ self ._worker_thread .join ()
140132
141133 # ----------------------------------------------------------------------
142134 def _reset_worker_thread (self ):
143- AsynchronousLogstashHandler ._worker_thread = None
135+ self ._worker_thread = None
144136
145137 # ----------------------------------------------------------------------
146138 def _close_transport (self ):
0 commit comments