Skip to main content

Opinionated Python logging config for local dev and Cloud Run/Functions

Project description

toolslog

Opinionated Python logging configuration. One import configures everything.

  • Locally: human-readable plain text to stdout
  • Cloud Run / Cloud Functions: structured JSON with severity field (auto-detected)
  • Zero dependencies — stdlib only

Install

pip install toolslog

Quick start

from toolslog import get_logger
logger = get_logger(__file__)

logger.debug("verbose detail")         # hidden by default (level=INFO)
logger.info("normal flow")
logger.warning("potential issue")
logger.error("something failed")
logger.critical("system-level failure")

Output (local):

2026-02-26 15:03:17,850 | INFO | main | normal flow
2026-02-26 15:03:17,851 | WARNING | main | potential issue
2026-02-26 15:03:17,851 | ERROR | main | something failed
2026-02-26 15:03:17,851 | CRITICAL | main | system-level failure

Output (Cloud Run — auto-detected):

{"severity": "INFO", "message": "normal flow", "logger": "main", ...}

Log level control

Default level is INFO. Override via LOG_LEVEL environment variable.

# everything DEBUG (all modules):
LOG_LEVEL=DEBUG python main.py

# check / set / unset in current shell session:
echo $LOG_LEVEL
export LOG_LEVEL=DEBUG
unset LOG_LEVEL

Per-module overrides (in your script):

import logging

# only this script to DEBUG (imported modules stay at INFO):
logger.setLevel(logging.DEBUG)

# only a specific library to DEBUG:
logging.getLogger("toolsbq").setLevel(logging.DEBUG)

# silence a noisy library:
logging.getLogger("toolsbq").setLevel(logging.WARNING)

Searching logs

grep "| ERROR |" app.log
grep "| WARNING |" app.log
grep -E "\| (ERROR|WARNING) \|" app.log

For libraries (toolsbq, toolssecret, etc.)

Libraries should not import toolslog. Just use the stdlib:

import logging
logger = logging.getLogger(__name__)

The calling application (which imports toolslog) configures the root logger. Libraries automatically inherit that configuration.

How it works

On import, toolslog:

  1. Detects environment (GCP vs local) via env vars (K_SERVICE, FUNCTION_TARGET, etc.)
  2. Clears any existing root logger handlers (e.g. from functions_framework)
  3. Adds a single handler with the appropriate formatter
  4. Sets the root level from LOG_LEVEL env var (default: INFO)

This runs once — Python caches the import, so multiple from toolslog import get_logger calls across modules are safe.

Note

This package is opinionated — it takes over the root logger. Use it in your own entry-point scripts, not in libraries you publish for others.

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

toolslog-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

toolslog-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file toolslog-0.1.0.tar.gz.

File metadata

  • Download URL: toolslog-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for toolslog-0.1.0.tar.gz
Algorithm Hash digest
SHA256 54ff63be84d148a64fefb07455f0371864ac26317f5a03ff5fec2a2f9f4a4f1f
MD5 eee13bd7d1bc61dc081770be0e569494
BLAKE2b-256 ed6dd6c8c6923a0512196567cb2d1eed8bcbe0e3e902ad99b44407cdb549d6d6

See more details on using hashes here.

File details

Details for the file toolslog-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: toolslog-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for toolslog-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43187dbcd0afb04665a72322f1f2035114eecc928ed35cde5c0a2b8053e71ab0
MD5 52006ba01487dfca85bbb7549e2a98a0
BLAKE2b-256 7e658724183131be257c7234767004a262df2f582fff64852be07a8983b5c06d

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