Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOG-4636 - update setup.py, update requests_futures, add gitignore #7

Merged
merged 1 commit into from Dec 3, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -0,0 +1,3 @@
.idea/
venv/
environment/
@@ -1,8 +1,6 @@
Python Logging Loggly Handler
-----------------------------

[![Build Status](https://travis-ci.org/psquickitjayant/loggly-python-handler.png?branch=master)](https://travis-ci.org/psquickitjayant/loggly-python-handler) [![Coverage Status](https://coveralls.io/repos/psquickitjayant/loggly-python-handler/badge.svg)](https://coveralls.io/r/psquickitjayant/loggly-python-handler)

A simple Python logging Loggly handler that can be used to send to a Loggly Gen2 https endpoint. Borrowed the extra fields concept from the graypy logging library. Check out Loggly's [Python logging documentation](https://www.loggly.com/docs/python-http/) to learn more.

## Installation
@@ -1,19 +1,21 @@
import logging
import logging.handlers

import socket
import traceback

from requests_futures.sessions import FuturesSession

session = FuturesSession()


def bg_cb(sess, resp):
def response_callback(resp, *args, **kwargs):
""" Don't do anything with the response """
pass


session.hooks['response'] = response_callback


class HTTPSHandler(logging.Handler):
def __init__(self, url, fqdn=False, localname=None, facility=None):
logging.Handler.__init__(self)
@@ -31,8 +33,8 @@ def get_full_message(self, record):
def emit(self, record):
try:
payload = self.format(record)
session.post(self.url, data=payload.encode("utf-8"), background_callback=bg_cb)
session.post(self.url, data=payload.encode("utf-8"))
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
self.handleError(record)
@@ -4,6 +4,7 @@

import loggly.handlers as handlers


class TestLogglyHandler(unittest.TestCase):
def setUp(self):
handlers.session = self.session = Mock()
@@ -29,9 +30,9 @@ def setUp(self):
'facility': 'record'
}

def test_bg_cb(self):
def test_response_callback(self):
""" the background callback should do nothing """
handlers.bg_cb(None, None)
handlers.response_callback(None, None)

def test_handler_init(self):
""" it should create a configured handler """
@@ -73,8 +74,7 @@ def test_emit(self):

handler.format.assert_called_once_with(self.record)

self.session.post.assert_called_once_with(
'url', data='msg', background_callback=handlers.bg_cb)
self.session.post.assert_called_once_with('url', data='msg'.encode('utf-8'))

def test_emit_interrupt(self):
""" it should raise the interrupt """
@@ -2,4 +2,4 @@ coverage==3.7.1
flake8==2.1.0
mock==1.0.1
nose==1.3.0
requests-futures==0.9.4
requests-futures==0.9.9
@@ -2,22 +2,28 @@

from setuptools import setup, find_packages

with open("README.md", "r") as fh:
long_description = fh.read()

setup(
name="loggly-python-handler",
version='1.0.0',
version='1.0.1',
description="Python logging handler that sends messages to Loggly",
long_description=long_description,
long_description_content_type="text/markdown",
keywords="loggly logging handler https",
author="psquickitjayant",
author_email="jayantvarshney018@gmail.com",
url="https://github.com/psquickitjayant/loggly-python-handler/",
author="Loggly",
author_email="support@loggly.com",
url="https://github.com/loggly/loggly-python-handler/",
license="MIT",
packages=find_packages(),
install_requires=[
"requests-futures >= 0.9.4",
"requests-futures >= 0.9.9",
],
include_package_data=True,
platform='any',
classifiers=[
'License :: OSI Approved :: MIT License',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers'
]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.