Skip to main content

Automatic function logging with decorators — output to SQLite, CSV, and Markdown

Project description

nfo

Automatic function logging with decorators — output to SQLite, CSV, and Markdown.

PyPI Python License

Zero-dependency Python package that automatically logs function calls using decorators. Captures arguments, types, return values, exceptions, and execution time — writes to SQLite, CSV, or Markdown.

Installation

pip install nfo

Quick Start

from nfo import log_call, catch

@log_call
def add(a: int, b: int) -> int:
    return a + b

@catch
def risky(x: float) -> float:
    return 1 / x

add(3, 7)       # logs: args, types, return value, duration
risky(0)        # logs exception, returns None (no crash)

Output (stderr):

2026-02-11 21:59:34 | DEBUG | nfo | add() | args=(3, 7) | -> 10 | [0.00ms]
2026-02-11 21:59:34 | ERROR | nfo | risky() | args=(0,) | EXCEPTION ZeroDivisionError: division by zero | [0.00ms]

Features

  • @log_call — logs entry/exit, args with types, return value, exceptions + traceback, duration
  • @catch — like @log_call but suppresses exceptions (returns configurable default)
  • SQLiteSink — persist logs to SQLite database
  • CSVSink — append logs to CSV file
  • MarkdownSink — write human-readable Markdown log files
  • Logger — central dispatcher with multiple sinks + optional stdlib logging forwarding
  • Zero dependencies — uses only Python standard library
  • Thread-safe — all sinks use locks

Sinks

SQLite

from nfo import Logger, log_call, SQLiteSink
from nfo.decorators import set_default_logger

logger = Logger(sinks=[SQLiteSink("logs.db")])
set_default_logger(logger)

@log_call
def fetch_user(user_id: int) -> dict:
    return {"id": user_id, "name": "Alice"}

fetch_user(42)
# Query: SELECT * FROM logs WHERE level = 'ERROR'

CSV

from nfo import Logger, log_call, CSVSink
from nfo.decorators import set_default_logger

logger = Logger(sinks=[CSVSink("logs.csv")])
set_default_logger(logger)

@log_call
def multiply(a: int, b: int) -> int:
    return a * b

multiply(6, 7)

Markdown

from nfo import Logger, log_call, MarkdownSink
from nfo.decorators import set_default_logger

logger = Logger(sinks=[MarkdownSink("logs.md")], propagate_stdlib=False)
set_default_logger(logger)

@log_call
def compute(x: float, y: float) -> float:
    return x ** y

compute(2.0, 10.0)

Multiple Sinks

from nfo import Logger, SQLiteSink, CSVSink, MarkdownSink

logger = Logger(sinks=[
    SQLiteSink("logs.db"),
    CSVSink("logs.csv"),
    MarkdownSink("logs.md"),
])

What Gets Logged

Each @log_call / @catch captures:

Field Description
timestamp UTC ISO-8601
level DEBUG (success) or ERROR (exception)
function_name Qualified function name
module Python module
args / kwargs Positional and keyword arguments
arg_types / kwarg_types Type names of each argument
return_value / return_type Return value and its type
exception / exception_type Exception message and class
traceback Full traceback on error
duration_ms Wall-clock execution time

Examples

See the examples/ directory:

Run any example:

pip install nfo
python examples/basic_usage.py

Development

git clone https://github.com/wronai/lg.git
cd lg
python -m venv venv && source venv/bin/activate
pip install -e ".[dev]"
pytest tests/ -v

License

Apache-2.0

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

nfo-0.1.12.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

nfo-0.1.12-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file nfo-0.1.12.tar.gz.

File metadata

  • Download URL: nfo-0.1.12.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for nfo-0.1.12.tar.gz
Algorithm Hash digest
SHA256 2fb60a5108fe70aa3b6ed7d56a78792e92a0a2ee68650c7cce134680abab5a1d
MD5 8f964d4bb06e8d8b3448c857231c77e0
BLAKE2b-256 88c74f525e849466f735b3064f66264fb13209e1d5157b78c1a0d7d0b44da49e

See more details on using hashes here.

File details

Details for the file nfo-0.1.12-py3-none-any.whl.

File metadata

  • Download URL: nfo-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for nfo-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 883f401cb4f38a36233172fcc8331a370b96e23feb6e162269f25eb765a256e7
MD5 bdd9159212b9a5b5e145df0478885a35
BLAKE2b-256 76fb5cebde0d905433b90ae8d8d649ab604362e3e8d5fb9497e2c90ef18fe20f

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