Skip to main content

A Google Cloud Platform compliant structured logging library

Project description

Louder Logging

A Google Cloud Logging compliant structured logging library.

Setup

The following environment variables must be set for logging to function.

# The name of the actual application running, e.g cloud run service / job name
export LDR_APPLICATION_NAME=application-name
# The version of the application, example here for poetry environments
export LDR_APPLICATION_VERSION=$(poetry version -s)
# The name of the service, can be the same as application name if the service is only
# one component, but in larger projects will be the name of the service offering rather
# than just the application name.
export LDR_APPLICATION_SERVICE_NAME=application-service-name
# The commit hash that this version of the code was committed with.
export LDR_APPLICATION_COMMIT_HASH=$(git rev-parse HEAD)

Examples

import ldr.logging
import logging

ldr.logging.setup(logging.DEBUG)

logging.info("Hello, world!")

entry = ldr.logging.Entry()
logging.warning()

Will write the following to stderr

{"logging.googleapis.com/diagnostic": {"instrumentation_source": [{"name": "python", "version": "3.11.3"}]},"severity": "INFO", "logging.googleapis.com/labels": {"python_logger": "google.cloud.logging_v2.handlers.structured_log"}, "logging.googleapis.com/trace": "", "logging.googleapis.com/spanId": "", "logging.googleapis.com/trace_sampled": false, "logging.googleapis.com/sourceLocation": {"line": 149, "file": "/Users/you/Library/Caches/pypoetry/virtualenvs/my-application-N_XRT3hE-py3.11/lib/python3.11/site-packages/google/cloud/logging_v2/handlers/structured_log.py", "function": "emit_instrumentation_info"}, "httpRequest": {} }
{"message": "Hello, world!","severity": "INFO", "logging.googleapis.com/labels": {"python_logger": "root"}, "logging.googleapis.com/trace": "", "logging.googleapis.com/spanId": "", "logging.googleapis.com/trace_sampled": false, "logging.googleapis.com/sourceLocation": {"line": 6, "file": "/Users/you/project/src/main.py", "function": "<module>"}, "httpRequest": {} }
{"client": "LOUD", "message": "Something weird happened but we've handled it", "app": {"name": "application-name", "version": "0.1.0", "service_name": "application-service-name", "commit_hash": "ea09ae9cc6768c50fcee903ed054556e5bfc8347"}, "extra": {"foo": "bar"},"severity": "WARNING", "logging.googleapis.com/labels": {"python_logger": "root"}, "logging.googleapis.com/trace": "", "logging.googleapis.com/spanId": "", "logging.googleapis.com/trace_sampled": false, "logging.googleapis.com/sourceLocation": {"line": 13, "file": "/Users/you/project/src/main.py", "function": "<module>"}, "httpRequest": {} }

Copyright

This project is licensed under the MIT license.

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

ldr_logging-0.1.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

ldr_logging-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file ldr_logging-0.1.1.tar.gz.

File metadata

  • Download URL: ldr_logging-0.1.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.14 Darwin/23.6.0

File hashes

Hashes for ldr_logging-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1cee1726c2a7f434e34370f36af1932b1a8151868c6ae1406d301b6dceafdc7a
MD5 e976878dfe85c4cb991ca7677c9ed132
BLAKE2b-256 6e36331201f8cada25e9275bda5cb05deab36292fc826a0e4fc69c0a56d1331f

See more details on using hashes here.

File details

Details for the file ldr_logging-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ldr_logging-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.14 Darwin/23.6.0

File hashes

Hashes for ldr_logging-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f77072276ae57e077784ddd8c94e421967ca094aad03b86b48fac184d5c6c0c5
MD5 c61475744de1c650f5fbe4ed7de5b143
BLAKE2b-256 efdd3d738bfedc1939cb52f312d22a94770b53ee28e099b17448b0d504d8412f

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