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.3.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kubi_ecs_logger-0.1.3-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kubi_ecs_logger-0.1.3.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for kubi_ecs_logger-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0ff28787e494b99f78b1f7388b46e60f4456328bef4e72c2b9687e737b41f900
MD5 5e9405a1e8820705520050554938aa87
BLAKE2b-256 ba15dec980f3801ea14cbf8c6a7a406c028ee5759999735049d149124c0d58ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kubi_ecs_logger-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8a7e1dc80c46c926a3bed825fa3f9c99a02748f93ba4d8af89c96fac33a337b2
MD5 983a57437a60118b4d620cbe1aa2a43c
BLAKE2b-256 89498b9c3357363d95007f07d3f0d581e360e018062612e91bfbffc15cd4d1d3

See more details on using hashes here.

Supported by

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