Browse Source

Bug fixes and ci (#70)

* bug fixes
* Added CI: tests and auto release
opensearch
Tamir Michaeli 3 years ago
committed by GitHub
parent
commit
f4713a6217
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 69 additions and 21 deletions
  1. +27
    -0
      .github/workflows/auto-release.yml
  2. +14
    -0
      .github/workflows/tests.yml
  3. +9
    -4
      README.md
  4. +5
    -3
      logzio/handler.py
  5. +3
    -1
      logzio/logger.py
  6. +2
    -4
      logzio/sender.py
  7. +1
    -1
      setup.py
  8. +2
    -5
      tests/test_logzioHandler.py
  9. +6
    -3
      tox.ini

+ 27
- 0
.github/workflows/auto-release.yml View File

@ -0,0 +1,27 @@
name: Pypi Release
on:
workflow_run:
workflows: ["CI Tests"]
branches: [master]
types:
- completed
# Allows you to run this workflow manually from the Actions tab
jobs:
build-and-release:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v3.0.0
with:
python-version: '3.x'
- name: "Install dependencies"
run: |
python3 -m pip install setuptools wheel twine
- name: "Build and uploads to PyPI"
run: |
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_REPO_TOKEN }}

+ 14
- 0
.github/workflows/tests.yml View File

@ -0,0 +1,14 @@
name: CI Tests
on: [push]
jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v3.0.0
with:
python-version: '3.x'
- name: Install tox
run: pip install tox
- name: Run tox
run: python -m tox

+ 9
- 4
README.md View File

@ -32,6 +32,7 @@ Travis CI will build this handler and test against:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
We can't ensure compatibility to any other version, as we can't test it automatically.
@ -76,7 +77,7 @@ format={"additional_field": "value"}
- 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")
- Network timeout, in seconds, int or float, for sending the logs to logz.io. (defaults to 10)
- Retries number (retry_no), in seconds (defaults to 4).
- Retries number (retry_no, defaults to 4).
- Retry timeout (retry_timeout) in seconds (defaults to 2).
Please note, that you have to configure those parameters by this exact order.
@ -213,15 +214,19 @@ LOGGING = {
Please note that if you are using `python 3.8` it is preferred to use the `logging.config.dictConfig` method, as mentioned in [python's documentation](https://docs.python.org/3/library/logging.config.html#configuration-file-format).
## Release Notes
- 3.1.1
- Bug fixes (issue #68, exception message formatting)
- Added CI: Tests and Auto release
- 3.1.0
- Bug fixes
- Retry number and timeout is now configurable
- 3.0.0
- Deprecated `python2.7` & `python3.4`
- Changed log levels on `_flush_queue()` method (@hilsenrat)
<details>
<summary markdown="span"> Expand to check old versions </summary>
- 3.0.0
- Deprecated `python2.7` & `python3.4`
- Changed log levels on `_flush_queue()` method (@hilsenrat)
- 2.0.15
- Added flusher decorator for serverless platforms(@mcmasty)


+ 5
- 3
logzio/handler.py View File

@ -98,13 +98,15 @@ class LogzioHandler(logging.Handler):
if message.exc_info:
return_json['exception'] = self.format_exception(message.exc_info)
# # We want to ignore default logging formatting on exceptions
# # As we handle those differently directly into exception field
# # We want to ignore default logging formatting on exceptions
# # As we handle those differently directly into exception field
formatted_message = self.format(message)
# Exception with multiple fields, apply them to log json.
if isinstance(formatted_message, dict):
return_json.update(formatted_message)
else:
# No exception, apply default formatted message
elif not message.exc_info:
return_json['message'] = formatted_message
return_json.update(self.extra_fields(message))


+ 3
- 1
logzio/logger.py View File

@ -7,7 +7,9 @@ def get_logger(debug):
def get_stdout_logger(debug):
return __get_logger(debug, __name__ + '_stdout', logging.StreamHandler(sys.stdout))
stdout_logger = __get_logger(debug, __name__ + '_stdout', logging.StreamHandler(sys.stdout))
stdout_logger.propagate = False
return stdout_logger
def __get_logger(debug, name, handler=None):


+ 2
- 4
logzio/sender.py View File

@ -40,7 +40,6 @@ class LogzioSender:
self.token = token
self.url = '{}/?token={}'.format(url, token)
self.logs_drain_timeout = logs_drain_timeout
self.logger = get_logger(debug)
self.stdout_logger = get_stdout_logger(debug)
self.backup_logs = backup_logs
self.network_timeout = network_timeout
@ -57,7 +56,6 @@ class LogzioSender:
self._initialize_sending_thread()
def __del__(self):
del self.logger
del self.stdout_logger
del self.backup_logs
del self.queue
@ -93,7 +91,7 @@ class LogzioSender:
try:
self._flush_queue()
except Exception as e:
self.logger.debug(
self.stdout_logger.debug(
'Unexpected exception while draining queue to Logz.io, '
'swallowing. Exception: %s', e)
@ -165,7 +163,7 @@ class LogzioSender:
self.stdout_logger.error(
'Could not send logs to Logz.io after %s tries, '
'backing up to local file system', self.number_of_retries)
backup_logs(logs_list, self.logger)
backup_logs(logs_list, self.stdout_logger)
del logs_list


+ 1
- 1
setup.py View File

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


+ 2
- 5
tests/test_logzioHandler.py View File

@ -159,7 +159,6 @@ class TestLogzioHandler(TestCase):
formatted_message["exception"] = formatted_message["exception"].replace(os.path.abspath(__file__), "")
formatted_message["exception"] = re.sub(r", line \d+", "", formatted_message["exception"])
formatted_message["message"] = formatted_message["message"].replace(os.path.abspath(__file__), "")
self.assertDictEqual(
{
@ -167,10 +166,8 @@ class TestLogzioHandler(TestCase):
'line_number': 10,
'log_level': 'NOTSET',
'logger': 'my-logger',
'message': f'exception test:\nTraceback (most recent call last):\n File "", line 142, in test_exc\n raise '
'ValueError("oops.")\nValueError: oops.',
'exception': 'Traceback (most recent call last):\n\n File "", in test_exc\n raise ValueError('
'"oops.")\n\nValueError: oops.\n',
'message': 'exception test:',
'exception': 'Traceback (most recent call last):\n\n File "", in test_exc\n raise ValueError("oops.")\n\nValueError: oops.\n',
'path_name': 'handler_test.py',
'type': 'python'
},


+ 6
- 3
tox.ini View File

@ -1,6 +1,6 @@
[tox]
minversion = 1.7.2
envlist = flake8, py3flake8, py35, py36, py37, py38, pypy, pypy3
envlist = flake8, py3flake8, py35, py36, py37, py38, py39, pypy, pypy3
skip_missing_interpreters = true
[testenv]
@ -13,11 +13,14 @@ passenv = CI TRAVIS TRAVIS_*
commands = pytest --cov-report term-missing --cov logzio tests -v
[testenv:flake8]
basepython = python3.8
basepython = python3.9
deps = flake8
commands = flake8 logzio
[testenv:py3flake8]
basepython = python3.8
basepython = python3.9
deps = flake8
commands = flake8 logzio
[gh-actions]
python = 3.9: py39

Loading…
Cancel
Save