Browse Source

Fix conflicts with upstream

opensearch
nir0s 7 years ago
parent
commit
344d4e85b0
6 changed files with 30 additions and 5 deletions
  1. +0
    -3
      .gitignore
  2. +1
    -0
      README.md
  3. +5
    -0
      logzio/sender.py
  4. +1
    -1
      setup.py
  5. +1
    -1
      tests/mockLogzioListener/listener.py
  6. +22
    -0
      tests/test_logzioSender.py

+ 0
- 3
.gitignore View File

@ -57,6 +57,3 @@ coverage.xml
*.iml *.iml
*COMMIT_MSG *COMMIT_MSG
# QuickBuild
.qbcache/

+ 1
- 0
README.md View File

@ -147,6 +147,7 @@ LOGGING = {
- appname - Your django app - appname - Your django app
## Release Notes ## Release Notes
- 2.0.7 - Make sure sending thread is alive after fork (Thanks @jo-tham!)
- 2.0.6 - Add "flush()" method to manually drain the queue (Thanks @orenmazor!) - 2.0.6 - Add "flush()" method to manually drain the queue (Thanks @orenmazor!)
- 2.0.5 - Support for extra fields - 2.0.5 - Support for extra fields
- 2.0.4 - Publish package as source along wheel, and supprt python3 packagin (Thanks @cchristous!) - 2.0.4 - Publish package as source along wheel, and supprt python3 packagin (Thanks @cchristous!)


+ 5
- 0
logzio/sender.py View File

@ -44,13 +44,18 @@ class LogzioSender:
# Create a queue to hold logs # Create a queue to hold logs
self.queue = queue.Queue() self.queue = queue.Queue()
self._initialize_sending_thread()
def _initialize_sending_thread(self):
self.sending_thread = Thread(target=self._drain_queue) self.sending_thread = Thread(target=self._drain_queue)
self.sending_thread.daemon = False self.sending_thread.daemon = False
self.sending_thread.name = 'logzio-sending-thread' self.sending_thread.name = 'logzio-sending-thread'
self.sending_thread.start() self.sending_thread.start()
def append(self, logs_message): def append(self, logs_message):
if not self.sending_thread.is_alive():
self._initialize_sending_thread()
# Queue lib is thread safe, no issue here # Queue lib is thread safe, no issue here
self.queue.put(json.dumps(logs_message)) self.queue.put(json.dumps(logs_message))


+ 1
- 1
setup.py View File

@ -4,7 +4,7 @@ from setuptools import setup, find_packages
setup( setup(
name="logzio-python-handler", name="logzio-python-handler",
version='2.0.6',
version='2.0.7',
description="Logging handler to send logs to your Logz.io account with bulk SSL", description="Logging handler to send logs to your Logz.io account with bulk SSL",
keywords="logging handler logz.io bulk https", keywords="logging handler logz.io bulk https",
author="roiravhon", author="roiravhon",


+ 1
- 1
tests/mockLogzioListener/listener.py View File

@ -73,7 +73,7 @@ class MockLogzioListener:
return len(self.logs_list) return len(self.logs_list)
def clear_logs_buffer(self): def clear_logs_buffer(self):
self.logs_list = []
self.logs_list[:] = []
def set_server_error(self): def set_server_error(self):
self.persistent_flags.set_server_error() self.persistent_flags.set_server_error()


+ 22
- 0
tests/test_logzioSender.py View File

@ -21,6 +21,7 @@ def _find(pattern, path):
class TestLogzioSender(TestCase): class TestLogzioSender(TestCase):
def setUp(self): def setUp(self):
self.logzio_listener = listener.MockLogzioListener() self.logzio_listener = listener.MockLogzioListener()
self.logzio_listener.clear_logs_buffer()
self.logzio_listener.clear_server_error() self.logzio_listener.clear_server_error()
self.logs_drain_timeout = 1 self.logs_drain_timeout = 1
@ -106,3 +107,24 @@ class TestLogzioSender(TestCase):
with open(failure_files[0], "r") as f: with open(failure_files[0], "r") as f:
line = f.readline() line = f.readline()
self.assertTrue(log_message in line) self.assertTrue(log_message in line)
def test_can_send_after_fork(self):
childpid = os.fork()
child_log_message = 'logged from child process'
parent_log_message = 'logged from parent process'
if childpid == 0:
# Log from the child process
self.logger.info(child_log_message)
time.sleep(self.logs_drain_timeout * 2)
os._exit(0)
# Wait for the child process to finish
os.waitpid(childpid, 0)
# log from the parent process
self.logger.info(parent_log_message)
time.sleep(self.logs_drain_timeout * 2)
# Ensure listener receive all log messages
self.assertTrue(self.logzio_listener.find_log(child_log_message))
self.assertTrue(self.logzio_listener.find_log(parent_log_message))

Loading…
Cancel
Save