Skip to content

Logging

Vayu exposes a single named logger, L = logging.getLogger("vayu"), with a NullHandler already attached. Importing the library does not mutate the root logger or the global logging config, so pulling vayulib into a larger app won't duplicate log lines or override your formatters.

Shorthand methods

For quick scripts and REPL use:

from vayu import L

L.i("info")       # L.info
L.d("debug")      # L.debug
L.e("error")      # L.error
L.w("warn")       # L.warning
L.c("critical")   # L.critical

Memory-annotated logs

L.mem("msg") appends an RSS snapshot to the message — handy for long-running jobs:

from vayu import L
L.mem("finished ingest batch")
# INFO> finished ingest batch [mem: 1.2 GiB]

By default it reads /proc/<pid>/statm (Linux). If that file isn't available (e.g. macOS), it falls back to psutil.Process().memory_info().rss — install psutil yourself if you need the fallback.

configure_logging() — opt-in

For parity with the previous stdout-with-timezone behavior:

import vayu
vayu.configure_logging(level="INFO", tz="Asia/Kolkata")

What it does:

  • Removes any non-NullHandler already on the vayu logger.
  • Attaches a StreamHandler pointed at sys.stdout (override via stream=).
  • Uses a formatter that renders timestamps in the given IANA timezone (ISO-8601, seconds precision).
  • Sets L.propagate = False so the lines don't also go to the root logger.
  • Quiets asyncio to WARNING.

Defaults:

  • level$LOG_LEVEL or "INFO".
  • tz$TZ or "UTC".

Configuring yourself

If your app already has a logging setup, skip configure_logging() entirely and configure the "vayu" logger like any other:

import logging

handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("%(name)s %(levelname)s %(message)s"))

vayu_logger = logging.getLogger("vayu")
vayu_logger.addHandler(handler)
vayu_logger.setLevel(logging.INFO)

See also