Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit 19127c8

Browse files
oschulzSamgkreuzer
authored andcommitted
KIT-1033 made worker thread init dynamic
1 parent 357b373 commit 19127c8

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

docs/conf.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#
1919
import os
2020
import sys
21+
22+
import setup
23+
2124
sys.path.insert(0, os.path.abspath('..'))
2225

2326
import logstash_async
@@ -56,7 +59,7 @@
5659
# built documents.
5760
#
5861
# The short X.Y version.
59-
version = logstash_async.__version__
62+
version = setup.VERSION
6063
# The full version, including alpha/beta/rc tags.
6164
release = version
6265

logstash_async/__init__.py

-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
# -*- coding: utf-8 -*-
2-
#
3-
# This software may be modified and distributed under the terms
4-
# of the MIT license. See the LICENSE file for details.
5-
6-
__version__ = '2.3.2'
7-
8-
# When using an in-memory only cache, this persists the cache through
9-
# thread failures, shutdowns, and restarts.
10-
EVENT_CACHE = {}

logstash_async/handler.py

+10-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from logstash_async.formatter import LogstashFormatter
1010
from logstash_async.utils import safe_log_via_print
1111
from logstash_async.worker import LogProcessingWorker
12-
import logstash_async
1312
from .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

Comments
 (0)