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 | INFO | main | run | normal flow
2026-02-26 15:03:17 | WARNING | main | run | potential issue
2026-02-26 15:03:17 | ERROR | main | run | something failed
2026-02-26 15:03:17 | CRITICAL | main | run | 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)

# suppress urllib3 connection/retry warnings:
logging.getLogger("urllib3").setLevel(logging.WARNING)

# suppress google-auth / google-api / discovery noise:
logging.getLogger("google").setLevel(logging.WARNING)
logging.getLogger("googleapiclient.discovery_cache").setLevel(logging.ERROR)

Searching logs

# errors and tracebacks:
grep -E "(\| ERROR \||\| CRITICAL \||Traceback|Error:|Exception:)" app.log

# warnings and above:
grep -E "\| (WARNING|ERROR|CRITICAL) \|" app.log

# specific module:
grep "| toolsbq |" app.log

# specific function:
grep "| fetch_data |" 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.1.tar.gz (6.1 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.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toolslog-0.1.1.tar.gz
  • Upload date:
  • Size: 6.1 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.1.tar.gz
Algorithm Hash digest
SHA256 070ac429fbcd3625394b46d47654e4b2be26aeebd03a447bb784d637f1306edd
MD5 17fe3b0dbc76f6b427ee31a411d746c9
BLAKE2b-256 489441d6afdb4fe6f57646803618d9ea72a8198c9b48138f6978d8eba84bb58c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toolslog-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 afe5b1cc941151cc2a24fbf191b83e74175b5b03cbd8f57bb2494bb4a479357d
MD5 63721cd0018f3f2842f80651445fccc0
BLAKE2b-256 0999bcc38c5fabeddfcdb0b4c92f6b5088fbfddad203087dd56d4a11ea2b1ca9

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