Skip to main content

Python bindings for the Polyglot native structured logger

Project description

polyglot-logger

Python bindings for Polyglot — a shared Go logging core with a C ABI. Same polyglot.yaml, JSON shape, and sinks as the Node and .NET packages. Native libs ship in the wheel (Linux, Windows, macOS arm64); no Go/CGO required.

Current line: 0.3.x.

pip install polyglot-logger
from polyglot_logger import Logger

with Logger(service="api", stdout=True) as log:
    log.info("hello", user_id=1)

__exit__ calls close(). Side-by-side APIs: sdk.md.

Config file (optional)

Constructors load polyglot.yaml in the native core (POLYGLOT_CONFIG → cwd → parents, stop at .git). No PyYAML required for that path. Kwargs override file keys.

# polyglot.yaml (repo root)
service: payments-api
environment: prod
level: info
stdout: true
file:
  enabled: true
  path: /var/log/payments.log
Logger(service="payments-api")  # sinks from YAML

Full schema: configuration · zero-config.

Levels, fields, lifecycle

from polyglot_logger import Logger, Level

with Logger(
    "payments-api",
    environment="prod",
    level="info",
    stdout=True,
) as log:
    log.set_fields({"region": "us-east"})
    req = log.with_fields(request_id="r1")  # or log.bind(...)
    req.info("order created", order_id=123, amount=42.5)
    req.log_simple(Level.ERROR, "payment failed")
    req.close()
    log.flush()
  • Levels: tracefatal (fatal does not exit the process).
  • Prefer with_fields / bind for per-request context; avoid sharing set_fields across threads for request data.
  • One instance is fine for concurrent log / flush / stats / set_fields. Close from a single owner (or use the context manager).

Native library

Published wheels include platform natives. For a local monorepo build:

export POLYGLOT_LOGGER_LIB=$PWD/dist/liblogger.so   # logger.dll / liblogger.dylib

Intel Macs: arm64 is what ships today; set POLYGLOT_LOGGER_LIB for amd64 until CI covers it.

From source

git clone --recurse-submodules https://github.com/kishankumarhs/Polyglot.git
cd Polyglot && make build-native
pip install -e bindings/python

Docs

Polyglot is for multi-language stacks that want one ops model — shared config and sinks without reimplementing them per language.

Repos: polyglot-py · core: Polyglot

MIT

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

polyglot_logger-0.3.3.tar.gz (31.8 MB view details)

Uploaded Source

Built Distribution

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

polyglot_logger-0.3.3-py3-none-any.whl (31.9 MB view details)

Uploaded Python 3

File details

Details for the file polyglot_logger-0.3.3.tar.gz.

File metadata

  • Download URL: polyglot_logger-0.3.3.tar.gz
  • Upload date:
  • Size: 31.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.15

File hashes

Hashes for polyglot_logger-0.3.3.tar.gz
Algorithm Hash digest
SHA256 94406de67fbb334b40118050b4249367b1ce43615a355b0505c4e22054c024f9
MD5 3c18d86aeffed46c171cd6ba26db67e1
BLAKE2b-256 822be24ead52b1a13c75fcb277301edb4c077629729f249effd2ade1490cbe6e

See more details on using hashes here.

File details

Details for the file polyglot_logger-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for polyglot_logger-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 259cce2d9ee2edb2083b9e70af4dc0df34b3fc5044af1784a017bd927b3a26d2
MD5 ccf551129c5d11e4c2b37e72919f7a82
BLAKE2b-256 622dc8f07195758a9d2fd214ad232eecb8362488aeb85ee0066dd066f3c8ff42

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