Skip to main content

Logger based on Elasticsearch Common Schema.

Project description

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

Install

You can install the package from PyPi like this:

pip install kubi-ecs-logger

This package is only for Python 3.6 or newer.

Usage

# 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kubi_ecs_logger-0.1.2.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

kubi_ecs_logger-0.1.2-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file kubi_ecs_logger-0.1.2.tar.gz.

File metadata

  • Download URL: kubi_ecs_logger-0.1.2.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.15

File hashes

Hashes for kubi_ecs_logger-0.1.2.tar.gz
Algorithm Hash digest
SHA256 48e9a9a4b1e77b73631efd70d253386f34ca742da1b268b8e72624d903fff99b
MD5 138af6ab35435dc1bd368fa10122072e
BLAKE2b-256 717d10f197320bddb8d1eeff23f15b3b96ce403669a781ed0ac26b833b477bed

See more details on using hashes here.

File details

Details for the file kubi_ecs_logger-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for kubi_ecs_logger-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f35bd3ae9ac4c23977ac5307779c8e98cd7cef0025c11f7368e443d482dc30f6
MD5 ec2e60f7daeee76e95ac081ea3ae94f5
BLAKE2b-256 efeaf834ee42b7c536338f547ee6dd8c2a8e64c7889f756e4544d8e2b088e063

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page