Browse Source

Merge remote-tracking branch 'upstream/master'

opensearch
Ruda Porto Filgueiras 6 years ago
parent
commit
9c25f86c9f
6 changed files with 36 additions and 7 deletions
  1. +8
    -0
      .whitesource
  2. +5
    -2
      README.md
  3. +4
    -2
      logzio/handler.py
  4. +4
    -2
      logzio/sender.py
  5. +1
    -1
      setup.py
  6. +14
    -0
      tests/test_logzioSender.py

+ 8
- 0
.whitesource View File

@ -0,0 +1,8 @@
##########################################################
#### WhiteSource Integration configuration file ####
##########################################################
# Configuration #
#---------------#
ws.repo.scan=true
vulnerable.check.run.conclusion.level=failure

+ 5
- 2
README.md View File

@ -15,14 +15,15 @@ pip install logzio-python-handler
## Tested Python Versions ## Tested Python Versions
Travis CI will build this handler and test against: Travis CI will build this handler and test against:
- "2.7"
- "3.3"
- "2.7"
- "3.4" - "3.4"
- "3.5" - "3.5"
- "3.6" - "3.6"
We can't ensure compatibility to any other version, as we can't test it automatically. We can't ensure compatibility to any other version, as we can't test it automatically.
**Note**: The Logz.io Python Handler no longer tests Python 3.3 (which was [end-of-lifed](https://www.python.org/dev/peps/pep-0398/#id11) in 2017).
To run tests: To run tests:
```bash ```bash
@ -62,6 +63,7 @@ format={"additional_field": "value"}
- Time to sleep between draining attempts (defaults to "3") - Time to sleep between draining attempts (defaults to "3")
- Logz.io Listener address (defaults to "https://listener.logz.io:8071") - Logz.io Listener address (defaults to "https://listener.logz.io:8071")
- Debug flag. Set to True, will print debug messages to stdout. (defaults to "False") - Debug flag. Set to True, will print debug messages to stdout. (defaults to "False")
- Backup logs flag. Set to False, will disable the local backup of logs in case of failure. (defaults to "True")
Please note, that you have to configure those parameters by this exact order. Please note, that you have to configure those parameters by this exact order.
i.e. you cannot set Debug to true, without configuring all of the previous parameters as well. i.e. you cannot set Debug to true, without configuring all of the previous parameters as well.
@ -147,6 +149,7 @@ LOGGING = {
- appname - Your django app - appname - Your django app
## Release Notes ## Release Notes
- 2.0.12 - Support disable logs local backup
- 2.0.11 - Completely isolate exception from the message - 2.0.11 - Completely isolate exception from the message
- 2.0.10 - Not ignoring formatting on exceptions - 2.0.10 - Not ignoring formatting on exceptions
- 2.0.9 - Support extra fields on exceptions too (Thanks @asafc64!) - 2.0.9 - Support extra fields on exceptions too (Thanks @asafc64!)


+ 4
- 2
logzio/handler.py View File

@ -16,7 +16,8 @@ class LogzioHandler(logging.Handler):
logzio_type="python", logzio_type="python",
logs_drain_timeout=3, logs_drain_timeout=3,
url="https://listener.logz.io:8071", url="https://listener.logz.io:8071",
debug=False):
debug=False,
backup_logs=True):
if not token: if not token:
raise LogzioException('Logz.io Token must be provided') raise LogzioException('Logz.io Token must be provided')
@ -27,7 +28,8 @@ class LogzioHandler(logging.Handler):
token=token, token=token,
url=url, url=url,
logs_drain_timeout=logs_drain_timeout, logs_drain_timeout=logs_drain_timeout,
debug=debug)
debug=debug,
backup_logs=backup_logs)
logging.Handler.__init__(self) logging.Handler.__init__(self)
def extra_fields(self, message): def extra_fields(self, message):


+ 4
- 2
logzio/sender.py View File

@ -32,11 +32,13 @@ class LogzioSender:
def __init__(self, def __init__(self,
token, url='https://listener.logz.io:8071', token, url='https://listener.logz.io:8071',
logs_drain_timeout=5, logs_drain_timeout=5,
debug=False):
debug=False,
backup_logs=True):
self.token = token self.token = token
self.url = '{}/?token={}'.format(url, token) self.url = '{}/?token={}'.format(url, token)
self.logs_drain_timeout = logs_drain_timeout self.logs_drain_timeout = logs_drain_timeout
self.logger = get_logger(debug) self.logger = get_logger(debug)
self.backup_logs = backup_logs
# Function to see if the main thread is alive # Function to see if the main thread is alive
self.is_main_thread_active = lambda: any( self.is_main_thread_active = lambda: any(
@ -144,7 +146,7 @@ class LogzioSender:
sleep(sleep_between_retries) sleep(sleep_between_retries)
sleep_between_retries *= 2 sleep_between_retries *= 2
if should_backup_to_disk:
if should_backup_to_disk and self.backup_logs:
# Write to file # Write to file
self.logger.info( self.logger.info(
'Could not send logs to Logz.io after %s tries, ' 'Could not send logs to Logz.io after %s tries, '


+ 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.11',
version='2.0.12',
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",


+ 14
- 0
tests/test_logzioSender.py View File

@ -108,6 +108,20 @@ class TestLogzioSender(TestCase):
line = f.readline() line = f.readline()
self.assertTrue(log_message in line) self.assertTrue(log_message in line)
def test_local_file_backup_disabled(self):
log_message = "Backup to local filesystem"
self.logzio_listener.set_server_error()
self.logger.handlers[0].logzio_sender.backup_logs = False
self.logger.info(log_message)
# Make sure no file is present
self.assertEqual(len(_find("logzio-failures-*.txt", ".")), 0)
time.sleep(2 * 2 * 2 * 2 * 2) # All of the retries
# Make sure no file was created
self.assertEqual(len(_find("logzio-failures-*.txt", ".")), 0)
def test_can_send_after_fork(self): def test_can_send_after_fork(self):
childpid = os.fork() childpid = os.fork()
child_log_message = 'logged from child process' child_log_message = 'logged from child process'


Loading…
Cancel
Save