Skip to main content

Opinionated Python logging

Project description

sysentropy

Opinionated Python logging for the recurring problem of: "I just need a decent logger, why am I formatting timestamps by hand again?"

sysentropy is a small Python library that writes plain logs to disk, colored logs to stdout, and gives you reusable timestamp, timing, and exception helpers so you can stop rebuilding the same logging glue in every project.

How This Repo Happened

This repo exists because writing the same logging setup in every project gets old fast.

One day it is:

  • "I'll just do a tiny logger wrapper."
  • then "I want colors."
  • then "I want a logfile too."
  • then "why is this handler duplicated?"
  • then "what was that timestamp format again?"

At that point the only rational response was obviously to make a library about it.

So this is the result: a lightweight package extracted from that exact cycle of mild annoyance, repeated enough times to become a design requirement. Very noble. Very serious. Entirely unnecessary until it suddenly isn't.

What It Does

  • plain logs on disk
  • colored logs on stdout
  • a small API built on top of the standard logging module
  • a reusable timestamp helper for logfile names and other boring-but-common cases
  • a timing decorator for quick execution-time logging
  • lightweight helpers for timed blocks and exception logging

Features

  • Linux-kernel-inspired level colors for console output
  • separate stdout and file formatters
  • simple get_logger() entrypoint
  • optional directory creation for file logging
  • handler reuse to avoid duplicate output
  • a configuration object that leaves room for future expansion
  • a timestamp() helper that returns YYYYMMDD_HHMMSS
  • a timing() decorator that logs function runtime
  • a time_block() context manager for inline timing
  • a log_exceptions() helper that logs tracebacks before re-raising
  • automatic color detection for TTY vs redirected output

Install

pip install sysentropy

Quick start

from sysentropy import get_logger, log_exceptions, time_block, timestamp, timing

logger = get_logger("demo", log_file=f"logs/demo-{timestamp()}.log")


@timing(logger=logger)
@log_exceptions(logger=logger)
def do_work() -> None:
    with time_block("startup", logger=logger):
        logger.info("service started")

logger.debug("debug message")
do_work()
logger.warning("disk usage high")
logger.error("request failed")
logger.critical("system halted")

Default output style:

2026-04-01 22:00:00 INFO     : service started
2026-04-01 22:00:00 WARNING  : disk usage high
2026-04-01 22:00:00 ERROR    : request failed

Timestamp Helper

If you only need the timestamp format, import it directly:

from sysentropy import timestamp

filename = f"run-{timestamp()}.log"

It returns values like:

20260401_223735

Timing Helper

Use timing() as a decorator when you want a quick runtime measurement in your logs:

from sysentropy import get_logger, timing

logger = get_logger("demo")


@timing(logger=logger, label="expensive task")
def expensive_task() -> None:
    ...

It logs lines like:

2026-04-02 09:15:00 INFO     : expensive task completed in 0.012384s

Timed Blocks

Use time_block() when you only want to time one section of a function:

from sysentropy import get_logger, time_block

logger = get_logger("demo")

with time_block("database warmup", logger=logger):
    ...

Exception Logging

Use log_exceptions() to log tracebacks before the exception keeps propagating:

from sysentropy import get_logger, log_exceptions

logger = get_logger("demo")


@log_exceptions(logger=logger)
def run_job() -> None:
    raise RuntimeError("boom")

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

sysentropy-0.1.1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

sysentropy-0.1.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sysentropy-0.1.1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for sysentropy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0718052cf28bdbf2bf4b6c7fc4307adbf8a3eedbc37c8f48722261ad7829373d
MD5 4c3a65f07276d3105ec999df0ea84124
BLAKE2b-256 4ef057ed10d0a10e93979fad6a817103683a587c0546ec5018a9289ffc25b2e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sysentropy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for sysentropy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d959176bba24e47c486c0e19d88e655047f87c73aed2bac169121f1b3cc97c31
MD5 f2946383f9f99ec80f8f03baab1ed76d
BLAKE2b-256 822a1dcc384b5358afb10f5148dffecf3fed37aa15cfab075b47c1dcddb71e38

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