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:5 | normal flow
2026-02-26 15:03:17 | WARNING | main | run:6 | potential issue
2026-02-26 15:03:17 | ERROR | main | run:7 | something failed
2026-02-26 15:03:17 | CRITICAL | main | run:8 | 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 (line number varies, so use a pattern):
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.2.tar.gz (6.2 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.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toolslog-0.1.2.tar.gz
  • Upload date:
  • Size: 6.2 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.2.tar.gz
Algorithm Hash digest
SHA256 cda18556d93bd666eda37d212447228811f7b133145b63da93f4dc34fb958855
MD5 573700712e0e80dbde66ffbdc7cbc097
BLAKE2b-256 8d8d621933ffac28ebe599d44906b30bb9463cf91c195a4f800faa840f90ca6d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toolslog-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5d8d79fc393fad1e9e5f484eaaa756178917b61721c49b6d4846611f98307921
MD5 c8209e1cede4ffc222e71098d6524334
BLAKE2b-256 35df369bf483c945205ac15b675e51d0c5b5c1627739706cf2440f9a71705bec

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