logmatic-python


Namelogmatic-python JSON
Version 0.1.7 PyPI version JSON
download
home_pagehttps://github.com/logmatic/logmatic-python
SummaryPython plugin to send logs to Logmatic.io
upload_time2017-01-18 09:52:29
maintainer
docs_urlNone
authorLogmatic.io support team
requires_python
licenseMIT
keywords logmatic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            logmatic-python
===============
*Link to the Logmatic.io documentation: http://doc.logmatic.io/docs/python*

Python helpers to send logs to Logmatic.io.

It mainly contains a proper JSON formatter and a socket handler that
streams logs directly to Logmatic.io - so no need to use a log shipper
if you don't wan't to.

Pre-requirements
================

To install this library, use the following command:

::

    pip install logmatic-python

Usage
=====

Use the JSON formatter
----------------------

To use the JSON formatter, simply associate it to any handler such as
the StreamHandler here.

.. code:: python

    import logmatic
    import logging

    logger = logging.getLogger()

    handler = logging.StreamHandler()
    handler.setFormatter(logmatic.JsonFormatter(extra={"hostname":socket.gethostname()}))

    logger.addHandler(handler)
    logger.setLevel(logging.INFO)

Once this setup is done, any child logger will use this configuration
(eg ``logging.getlogger("my_logger")``). As you can see, you can
associate any extra information to the base formatter such as the
hostname here or any environment variable you'll need depending of your
usage.

.. code:: python

    test_logger = logging.getLogger("test")
    test_logger.info("classic message", extra={"special": "value", "run": 12})

Returns the following format:

.. code:: javascript

    {
      "asctime": "2016-02-16T09:51:31Z",
      "name": "test", "processName": "MainProcess",
      "filename": "write_in_console.py",
      "funcName": "<module>",
      "levelname": "INFO",
      "lineno": 20,
      "module": "write_in_console",
      "threadName": "MainThread",
      "message": "classic message",
      "special": "value",
      "run": 12,
      "timestamp": "2016-02-16T09:51:31Z",
      "hostname": "<your_hostname>"
    }

Let's take some time here to understand what we have:

-  The default format is "%(asctime) %(name) %(processName) %(filename)
   %(funcName) %(levelname) %(lineno) %(module) %(threadName)
   %(message)". So that's why all these attributes are present on all
   the log events. If you need less, you can change the format when
   defining the formatter: ``logmatic.JsonFormatter(fmt="",...)``
-  The ``hostname`` attribute here is added all the time as it was
   defined on the root logger.
-  The ``special`` and ``run`` attributes were added specifically to
   this log event.

Good to know, an traceback from an exception is totally wrapped into the
JSON event. That's suppress the handling of multiline formatting:

.. code:: javascript

    {
      ...
      "exc_info": "Traceback (most recent call last):\n  File \"test/write_in_console.py\", line 24, in exception_test\n    raise Exception('test')\nException: test",
      ...
    }

Stream log straight to Logmatic.io
----------------------------------

The LogmaticHandler can be coupled to the JsonFormatter as follow:

.. code:: python

    import logmatic
    import logging

    logger = logging.getLogger()

    handler = logmatic.LogmaticHandler("<your_api_key>")
    handler.setFormatter(logmatic.JsonFormatter(extra={"hostname":socket.gethostname()}))

    logger.addHandler(handler)
    logger.setLevel(logging.INFO)

Don't forget to replace by the one provided on your Logmatic.io's
platform.

With this configuration, any log coming from your Python's application
will be sent to your platform and will fulfill the same format as
described in the previous section.

Please contact us if you want anything more to be added in this toolset!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/logmatic/logmatic-python",
    "name": "logmatic-python",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "logmatic",
    "author": "Logmatic.io support team",
    "author_email": "support@logmatic.io",
    "download_url": "https://files.pythonhosted.org/packages/f9/da/02d5dcdd0fbc3b0a074006773e7269da3468d98e06d7d95a9080166b0f61/logmatic-python-0.1.7.tar.gz",
    "platform": "",
    "description": "logmatic-python\n===============\n*Link to the Logmatic.io documentation: http://doc.logmatic.io/docs/python*\n\nPython helpers to send logs to Logmatic.io.\n\nIt mainly contains a proper JSON formatter and a socket handler that\nstreams logs directly to Logmatic.io - so no need to use a log shipper\nif you don't wan't to.\n\nPre-requirements\n================\n\nTo install this library, use the following command:\n\n::\n\n    pip install logmatic-python\n\nUsage\n=====\n\nUse the JSON formatter\n----------------------\n\nTo use the JSON formatter, simply associate it to any handler such as\nthe StreamHandler here.\n\n.. code:: python\n\n    import logmatic\n    import logging\n\n    logger = logging.getLogger()\n\n    handler = logging.StreamHandler()\n    handler.setFormatter(logmatic.JsonFormatter(extra={\"hostname\":socket.gethostname()}))\n\n    logger.addHandler(handler)\n    logger.setLevel(logging.INFO)\n\nOnce this setup is done, any child logger will use this configuration\n(eg ``logging.getlogger(\"my_logger\")``). As you can see, you can\nassociate any extra information to the base formatter such as the\nhostname here or any environment variable you'll need depending of your\nusage.\n\n.. code:: python\n\n    test_logger = logging.getLogger(\"test\")\n    test_logger.info(\"classic message\", extra={\"special\": \"value\", \"run\": 12})\n\nReturns the following format:\n\n.. code:: javascript\n\n    {\n      \"asctime\": \"2016-02-16T09:51:31Z\",\n      \"name\": \"test\", \"processName\": \"MainProcess\",\n      \"filename\": \"write_in_console.py\",\n      \"funcName\": \"<module>\",\n      \"levelname\": \"INFO\",\n      \"lineno\": 20,\n      \"module\": \"write_in_console\",\n      \"threadName\": \"MainThread\",\n      \"message\": \"classic message\",\n      \"special\": \"value\",\n      \"run\": 12,\n      \"timestamp\": \"2016-02-16T09:51:31Z\",\n      \"hostname\": \"<your_hostname>\"\n    }\n\nLet's take some time here to understand what we have:\n\n-  The default format is \"%(asctime) %(name) %(processName) %(filename)\n   %(funcName) %(levelname) %(lineno) %(module) %(threadName)\n   %(message)\". So that's why all these attributes are present on all\n   the log events. If you need less, you can change the format when\n   defining the formatter: ``logmatic.JsonFormatter(fmt=\"\",...)``\n-  The ``hostname`` attribute here is added all the time as it was\n   defined on the root logger.\n-  The ``special`` and ``run`` attributes were added specifically to\n   this log event.\n\nGood to know, an traceback from an exception is totally wrapped into the\nJSON event. That's suppress the handling of multiline formatting:\n\n.. code:: javascript\n\n    {\n      ...\n      \"exc_info\": \"Traceback (most recent call last):\\n  File \\\"test/write_in_console.py\\\", line 24, in exception_test\\n    raise Exception('test')\\nException: test\",\n      ...\n    }\n\nStream log straight to Logmatic.io\n----------------------------------\n\nThe LogmaticHandler can be coupled to the JsonFormatter as follow:\n\n.. code:: python\n\n    import logmatic\n    import logging\n\n    logger = logging.getLogger()\n\n    handler = logmatic.LogmaticHandler(\"<your_api_key>\")\n    handler.setFormatter(logmatic.JsonFormatter(extra={\"hostname\":socket.gethostname()}))\n\n    logger.addHandler(handler)\n    logger.setLevel(logging.INFO)\n\nDon't forget to replace by the one provided on your Logmatic.io's\nplatform.\n\nWith this configuration, any log coming from your Python's application\nwill be sent to your platform and will fulfill the same format as\ndescribed in the previous section.\n\nPlease contact us if you want anything more to be added in this toolset!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python plugin to send logs to Logmatic.io",
    "version": "0.1.7",
    "project_urls": {
        "Download": "https://github.com/logmatic/logmatic-python/tarball/0.1.6",
        "Homepage": "https://github.com/logmatic/logmatic-python"
    },
    "split_keywords": [
        "logmatic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f9da02d5dcdd0fbc3b0a074006773e7269da3468d98e06d7d95a9080166b0f61",
                "md5": "34c410bf1740d219f2538d6f7a6da888",
                "sha256": "0c15ac9f5faa6a60059b28910db642c3dc7722948c3cc940923f8c9039604342"
            },
            "downloads": -1,
            "filename": "logmatic-python-0.1.7.tar.gz",
            "has_sig": false,
            "md5_digest": "34c410bf1740d219f2538d6f7a6da888",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3338,
            "upload_time": "2017-01-18T09:52:29",
            "upload_time_iso_8601": "2017-01-18T09:52:29.751272Z",
            "url": "https://files.pythonhosted.org/packages/f9/da/02d5dcdd0fbc3b0a074006773e7269da3468d98e06d7d95a9080166b0f61/logmatic-python-0.1.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2017-01-18 09:52:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "logmatic",
    "github_project": "logmatic-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "logmatic-python"
}
        
Elapsed time: 2.35453s