python-logstash


Namepython-logstash JSON
Version 0.4.8 PyPI version JSON
download
home_pagehttps://github.com/vklochan/python-logstash
SummaryPython logging handler for Logstash.
upload_time2022-03-30 11:58:04
maintainerNone
docs_urlNone
authorVolodymyr Klochan
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            python-logstash
===============

Python logging handler for Logstash.
http://logstash.net/

Changelog
=========
0.4.8
  - Fixed Python 3 issues with JSON serialization.
0.4.7
  - Add couple of sensitive fields to the skip_list
0.4.6
  - Updated field names to match java counterparts supported by logstash crew
0.4.5
  - Allow passing exchange's routing key to AMQP handler
0.4.4
  - Fixed urllib import python3 compatibility.
  - Added long type to easy_types.
0.4.3
  - Added AMQP handler.
0.4.2
  - Updated README
  - Added ``tags`` parameter to handler
0.4.1
  - Added TCP handler.
0.3.1
  - Added support for Python 3
0.2.2
  - Split Handler into Handler and Formatter classes
0.2.1
  - Added support for the new JSON schema in Logstash 1.2.x. See details in
    http://tobrunet.ch/2013/09/logstash-1-2-0-upgrade-notes-included/ and
    https://logstash.jira.com/browse/LOGSTASH-675

    - Added ``version`` parameter. Available values: 1 (Logstash 1.2.x version format), 0 - default (previous version).


Installation
============

Using pip::

  pip install python-logstash

Usage
=====

``LogstashHandler`` is a custom logging handler which sends Logstash messages using UDP.

For example::

  import logging
  import logstash
  import sys

  host = 'localhost'

  test_logger = logging.getLogger('python-logstash-logger')
  test_logger.setLevel(logging.INFO)
  test_logger.addHandler(logstash.LogstashHandler(host, 5959, version=1))
  # test_logger.addHandler(logstash.TCPLogstashHandler(host, 5959, version=1))

  test_logger.error('python-logstash: test logstash error message.')
  test_logger.info('python-logstash: test logstash info message.')
  test_logger.warning('python-logstash: test logstash warning message.')

  # add extra field to logstash message
  extra = {
      'test_string': 'python version: ' + repr(sys.version_info),
      'test_boolean': True,
      'test_dict': {'a': 1, 'b': 'c'},
      'test_float': 1.23,
      'test_integer': 123,
      'test_list': [1, 2, '3'],
  }
  test_logger.info('python-logstash: test extra fields', extra=extra)

When using ``extra`` field make sure you don't use reserved names. From `Python documentation <https://docs.python.org/2/library/logging.html>`_.
     | "The keys in the dictionary passed in extra should not clash with the keys used by the logging system. (See the `Formatter <https://docs.python.org/2/library/logging.html#logging.Formatter>`_ documentation for more information on which keys are used by the logging system.)"

To use the AMQPLogstashHandler you will need to install pika first.

   pip install pika

For example::

  import logging
  import logstash

  test_logger = logging.getLogger('python-logstash-logger')
  test_logger.setLevel(logging.INFO)
  test_logger.addHandler(logstash.AMQPLogstashHandler(host='localhost', version=1))

  test_logger.info('python-logstash: test logstash info message.')
  try:
      1/0
  except:
      test_logger.exception('python-logstash-logger: Exception with stack trace!')



Using with Django
=================

Modify your ``settings.py`` to integrate ``python-logstash`` with Django's logging::

  LOGGING = {
    ...
    'handlers': {
        'logstash': {
            'level': 'DEBUG',
            'class': 'logstash.LogstashHandler',
            'host': 'localhost',
            'port': 5959, # Default value: 5959
            'version': 1, # Version of logstash event schema. Default value: 0 (for backward compatibility of the library)
            'message_type': 'logstash',  # 'type' field in logstash message. Default value: 'logstash'.
            'fqdn': False, # Fully qualified domain name. Default value: false.
            'tags': ['tag1', 'tag2'], # list of tags. Default: None.
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['logstash'],
            'level': 'DEBUG',
            'propagate': True,
        },
    },
    ...
  }

Example Logstash Configuration
==============================

Example Logstash Configuration (``logstash.conf``) for Receiving Events from python-logstash is::

  input {
    udp {
      port => 5959
      codec => json
    }
  }
  output {
    stdout {
      codec => rubydebug
    }
  }

For TCP input you need to change the logstash's input to ``tcp`` and modify django log handler's class to ``logstash.TCPLogstashHandler``

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vklochan/python-logstash",
    "name": "python-logstash",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Volodymyr Klochan",
    "author_email": "vklochan@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f7/3b/c3a957bbdd23859f07905fc3d1adfe89957217a347478c58409f0315cf1d/python-logstash-0.4.8.tar.gz",
    "platform": null,
    "description": "python-logstash\n===============\n\nPython logging handler for Logstash.\nhttp://logstash.net/\n\nChangelog\n=========\n0.4.8\n  - Fixed Python 3 issues with JSON serialization.\n0.4.7\n  - Add couple of sensitive fields to the skip_list\n0.4.6\n  - Updated field names to match java counterparts supported by logstash crew\n0.4.5\n  - Allow passing exchange's routing key to AMQP handler\n0.4.4\n  - Fixed urllib import python3 compatibility.\n  - Added long type to easy_types.\n0.4.3\n  - Added AMQP handler.\n0.4.2\n  - Updated README\n  - Added ``tags`` parameter to handler\n0.4.1\n  - Added TCP handler.\n0.3.1\n  - Added support for Python 3\n0.2.2\n  - Split Handler into Handler and Formatter classes\n0.2.1\n  - Added support for the new JSON schema in Logstash 1.2.x. See details in\n    http://tobrunet.ch/2013/09/logstash-1-2-0-upgrade-notes-included/ and\n    https://logstash.jira.com/browse/LOGSTASH-675\n\n    - Added ``version`` parameter. Available values: 1 (Logstash 1.2.x version format), 0 - default (previous version).\n\n\nInstallation\n============\n\nUsing pip::\n\n  pip install python-logstash\n\nUsage\n=====\n\n``LogstashHandler`` is a custom logging handler which sends Logstash messages using UDP.\n\nFor example::\n\n  import logging\n  import logstash\n  import sys\n\n  host = 'localhost'\n\n  test_logger = logging.getLogger('python-logstash-logger')\n  test_logger.setLevel(logging.INFO)\n  test_logger.addHandler(logstash.LogstashHandler(host, 5959, version=1))\n  # test_logger.addHandler(logstash.TCPLogstashHandler(host, 5959, version=1))\n\n  test_logger.error('python-logstash: test logstash error message.')\n  test_logger.info('python-logstash: test logstash info message.')\n  test_logger.warning('python-logstash: test logstash warning message.')\n\n  # add extra field to logstash message\n  extra = {\n      'test_string': 'python version: ' + repr(sys.version_info),\n      'test_boolean': True,\n      'test_dict': {'a': 1, 'b': 'c'},\n      'test_float': 1.23,\n      'test_integer': 123,\n      'test_list': [1, 2, '3'],\n  }\n  test_logger.info('python-logstash: test extra fields', extra=extra)\n\nWhen using ``extra`` field make sure you don't use reserved names. From `Python documentation <https://docs.python.org/2/library/logging.html>`_.\n     | \"The keys in the dictionary passed in extra should not clash with the keys used by the logging system. (See the `Formatter <https://docs.python.org/2/library/logging.html#logging.Formatter>`_ documentation for more information on which keys are used by the logging system.)\"\n\nTo use the AMQPLogstashHandler you will need to install pika first.\n\n   pip install pika\n\nFor example::\n\n  import logging\n  import logstash\n\n  test_logger = logging.getLogger('python-logstash-logger')\n  test_logger.setLevel(logging.INFO)\n  test_logger.addHandler(logstash.AMQPLogstashHandler(host='localhost', version=1))\n\n  test_logger.info('python-logstash: test logstash info message.')\n  try:\n      1/0\n  except:\n      test_logger.exception('python-logstash-logger: Exception with stack trace!')\n\n\n\nUsing with Django\n=================\n\nModify your ``settings.py`` to integrate ``python-logstash`` with Django's logging::\n\n  LOGGING = {\n    ...\n    'handlers': {\n        'logstash': {\n            'level': 'DEBUG',\n            'class': 'logstash.LogstashHandler',\n            'host': 'localhost',\n            'port': 5959, # Default value: 5959\n            'version': 1, # Version of logstash event schema. Default value: 0 (for backward compatibility of the library)\n            'message_type': 'logstash',  # 'type' field in logstash message. Default value: 'logstash'.\n            'fqdn': False, # Fully qualified domain name. Default value: false.\n            'tags': ['tag1', 'tag2'], # list of tags. Default: None.\n        },\n    },\n    'loggers': {\n        'django.request': {\n            'handlers': ['logstash'],\n            'level': 'DEBUG',\n            'propagate': True,\n        },\n    },\n    ...\n  }\n\nExample Logstash Configuration\n==============================\n\nExample Logstash Configuration (``logstash.conf``) for Receiving Events from python-logstash is::\n\n  input {\n    udp {\n      port => 5959\n      codec => json\n    }\n  }\n  output {\n    stdout {\n      codec => rubydebug\n    }\n  }\n\nFor TCP input you need to change the logstash's input to ``tcp`` and modify django log handler's class to ``logstash.TCPLogstashHandler``\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python logging handler for Logstash.",
    "version": "0.4.8",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "e2cbc75dd5417cb55acaa3a12bf3afac",
                "sha256": "d04e1ce11ecc107e4a4f3b807fc57d96811e964a554081b3bbb44732f74ef5f9"
            },
            "downloads": -1,
            "filename": "python-logstash-0.4.8.tar.gz",
            "has_sig": false,
            "md5_digest": "e2cbc75dd5417cb55acaa3a12bf3afac",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7074,
            "upload_time": "2022-03-30T11:58:04",
            "upload_time_iso_8601": "2022-03-30T11:58:04.095551Z",
            "url": "https://files.pythonhosted.org/packages/f7/3b/c3a957bbdd23859f07905fc3d1adfe89957217a347478c58409f0315cf1d/python-logstash-0.4.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-03-30 11:58:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "vklochan",
    "github_project": "python-logstash",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "python-logstash"
}
        
Elapsed time: 0.01780s