kubi-ecs-logger


Namekubi-ecs-logger JSON
Version 0.1.2 PyPI version JSON
download
home_page
SummaryLogger based on Elasticsearch Common Schema.
upload_time2022-12-13 16:39:34
maintainer
docs_urlNone
authorKumina
requires_python>=3.6, <4
license
keywords logging elasticsearch esc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img align="left" src="https://github.com/kumina/kubi_ecs_logger/blob/master/logo.png">
This Python module makes logging easy for your application.  
The logger outputs JSON formatted logs for ingesting into Elastic.  

The module implements the ECS (Elastic Common Schema) specification that
can be found at for quick reference: 
[ECS Field Reference](https://www.elastic.co/guide/en/ecs/current/ecs-field-reference.html#ecs-field-reference)

## Install
You can install the package from PyPi like this:
```bash
pip install kubi-ecs-logger
```
This package is only for Python 3.6 or newer.

## Usage
```python 
# Import 
from kubi_ecs_logger import Logger, Severity

# Set some defaults in the start of your app
# If in development mode the lib will output formatted json.
Logger().dev = True
# The minimum level of severity for outputing. E.g. If set to INFO then DEBUG logs will not 
# be printed to standard out
Logger().severity_output_level = Severity.INFO
# Set default key/value pairs for the different classes that will always be appended before final output
Logger().defaults = {
    "event": {
        "test": "test value"
    }
}

# Log loaded configuration
Logger().event(
    category="configuration",
    action="configuration loaded",
    dataset="The configuration is loaded from config.yaml"
).out(severity=Severity.INFO)

# Output
# {
#   "@timestamp": "2019-07-11T15:11:03.193759+00:00",
#   "event": {
#     "action": "configuration loaded",
#     "category": "configuration",
#     "dataset": "The configuration is loaded from config.yaml",
#     "test": "test value"  # From defaults
#   },
#   "logline": {
#     "level": "INFO"
#   }
# }

# Here is a little bit bigger example
Logger() \
    .event(category="requests", action="request received") \
    .url(path="/test", domain="test.com") \
    .source(ip="123.251.512.152") \
    .http_response(status_code=200) \
    .out(severity=Severity.INFO)

# And here is the output of this one
# {
#   "@timestamp": "2019-07-11T15:15:48.896921+00:00",
#   "event": {
#     "action": "request received",
#     "category": "requests",
#     "test": "test value"  # From defaults
#   },
#   "httpresponse": {
#     "status_code": "200"
#   },
#   "logline": {
#     "level": "INFO"
#   },
#   "source": {
#     "ip": "123.251.512.152"
#   },
#   "url": {
#     "domain": "test.com",
#     "path": "/test"
#   }
# }
```

## Dependencies
| name        | version |
|-------------|---------|
| marshmallow | 3.15.0  |

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "kubi-ecs-logger",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6, <4",
    "maintainer_email": "",
    "keywords": "logging elasticsearch esc",
    "author": "Kumina",
    "author_email": "bartv@kumina.nl",
    "download_url": "https://files.pythonhosted.org/packages/71/7d/10f197320bddb8d1eeff23f15b3b96ce403669a781ed0ac26b833b477bed/kubi_ecs_logger-0.1.2.tar.gz",
    "platform": null,
    "description": "<img align=\"left\" src=\"https://github.com/kumina/kubi_ecs_logger/blob/master/logo.png\">\nThis Python module makes logging easy for your application.  \nThe logger outputs JSON formatted logs for ingesting into Elastic.  \n\nThe module implements the ECS (Elastic Common Schema) specification that\ncan be found at for quick reference: \n[ECS Field Reference](https://www.elastic.co/guide/en/ecs/current/ecs-field-reference.html#ecs-field-reference)\n\n## Install\nYou can install the package from PyPi like this:\n```bash\npip install kubi-ecs-logger\n```\nThis package is only for Python 3.6 or newer.\n\n## Usage\n```python \n# Import \nfrom kubi_ecs_logger import Logger, Severity\n\n# Set some defaults in the start of your app\n# If in development mode the lib will output formatted json.\nLogger().dev = True\n# The minimum level of severity for outputing. E.g. If set to INFO then DEBUG logs will not \n# be printed to standard out\nLogger().severity_output_level = Severity.INFO\n# Set default key/value pairs for the different classes that will always be appended before final output\nLogger().defaults = {\n    \"event\": {\n        \"test\": \"test value\"\n    }\n}\n\n# Log loaded configuration\nLogger().event(\n    category=\"configuration\",\n    action=\"configuration loaded\",\n    dataset=\"The configuration is loaded from config.yaml\"\n).out(severity=Severity.INFO)\n\n# Output\n# {\n#   \"@timestamp\": \"2019-07-11T15:11:03.193759+00:00\",\n#   \"event\": {\n#     \"action\": \"configuration loaded\",\n#     \"category\": \"configuration\",\n#     \"dataset\": \"The configuration is loaded from config.yaml\",\n#     \"test\": \"test value\"  # From defaults\n#   },\n#   \"logline\": {\n#     \"level\": \"INFO\"\n#   }\n# }\n\n# Here is a little bit bigger example\nLogger() \\\n    .event(category=\"requests\", action=\"request received\") \\\n    .url(path=\"/test\", domain=\"test.com\") \\\n    .source(ip=\"123.251.512.152\") \\\n    .http_response(status_code=200) \\\n    .out(severity=Severity.INFO)\n\n# And here is the output of this one\n# {\n#   \"@timestamp\": \"2019-07-11T15:15:48.896921+00:00\",\n#   \"event\": {\n#     \"action\": \"request received\",\n#     \"category\": \"requests\",\n#     \"test\": \"test value\"  # From defaults\n#   },\n#   \"httpresponse\": {\n#     \"status_code\": \"200\"\n#   },\n#   \"logline\": {\n#     \"level\": \"INFO\"\n#   },\n#   \"source\": {\n#     \"ip\": \"123.251.512.152\"\n#   },\n#   \"url\": {\n#     \"domain\": \"test.com\",\n#     \"path\": \"/test\"\n#   }\n# }\n```\n\n## Dependencies\n| name        | version |\n|-------------|---------|\n| marshmallow | 3.15.0  |\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Logger based on Elasticsearch Common Schema.",
    "version": "0.1.2",
    "split_keywords": [
        "logging",
        "elasticsearch",
        "esc"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "ec2e60f7daeee76e95ac081ea3ae94f5",
                "sha256": "f35bd3ae9ac4c23977ac5307779c8e98cd7cef0025c11f7368e443d482dc30f6"
            },
            "downloads": -1,
            "filename": "kubi_ecs_logger-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ec2e60f7daeee76e95ac081ea3ae94f5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6, <4",
            "size": 23784,
            "upload_time": "2022-12-13T16:33:18",
            "upload_time_iso_8601": "2022-12-13T16:33:18.737691Z",
            "url": "https://files.pythonhosted.org/packages/ef/ea/f834ee42b7c536338f547ee6dd8c2a8e64c7889f756e4544d8e2b088e063/kubi_ecs_logger-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "138af6ab35435dc1bd368fa10122072e",
                "sha256": "48e9a9a4b1e77b73631efd70d253386f34ca742da1b268b8e72624d903fff99b"
            },
            "downloads": -1,
            "filename": "kubi_ecs_logger-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "138af6ab35435dc1bd368fa10122072e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6, <4",
            "size": 17032,
            "upload_time": "2022-12-13T16:39:34",
            "upload_time_iso_8601": "2022-12-13T16:39:34.952784Z",
            "url": "https://files.pythonhosted.org/packages/71/7d/10f197320bddb8d1eeff23f15b3b96ce403669a781ed0ac26b833b477bed/kubi_ecs_logger-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-13 16:39:34",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "kubi-ecs-logger"
}
        
Elapsed time: 0.02416s