Skip to main content

A lightweight, colorized Python terminal logger with auto exception capture and customizable format

Project description

Traceify

A lightweight, colorized Python terminal logger with auto exception capture, auto source-file detection, and a fully customizable log format.

Zero dependencies — uses only Python's standard library.


Installation

pip install Traceify

Quick Start

from Traceify import Traceify

log = Traceify("my_app")

log.debug("Starting up...")
log.info("Server running on port 8080")
log.warning("Memory usage above 80%")
log.error("Database connection failed")
log.critical("Disk full — shutting down!")

Output:

2026-04-13 11:00:00  [DEBUG   ]  [my_app]  Starting up...  @app.py
2026-04-13 11:00:00  [INFO    ]  [my_app]  Server running on port 8080  @app.py
2026-04-13 11:00:00  [WARNING ]  [my_app]  Memory usage above 80%  @app.py
2026-04-13 11:00:00  [ERROR   ]  [my_app]  Database connection failed  @app.py
2026-04-13 11:00:00  [CRITICAL]  [my_app]  Disk full — shutting down!  @app.py

Features

✅ Auto Exception Capture

Call any log method inside an except block — the active exception is automatically appended. No extra code needed.

try:
    result = 10 / 0
except ZeroDivisionError:
    log.error("Math operation failed")
# Output: ... [ERROR   ]  [my_app]  Math operation failed  (ZeroDivisionError: division by zero)  @app.py

✅ Auto Source File Detection

Every log line automatically shows which file it came from — useful when logs from multiple files appear together.

2026-04-13 11:00:00  [INFO    ]  [api]  Request received  @routes.py
2026-04-13 11:00:00  [ERROR   ]  [db]   Query failed      @database.py

✅ Customizable Format

Choose exactly which fields to show and in what order using the fmt parameter.

Available fields: "timestamp", "level", "name", "message", "exception", "file"

# Only level, message, and source file
log = Traceify("app", fmt=["level", "message", "file"])
log.info("Compact output")
# → [INFO    ]  Compact output  @app.py

# Only timestamp and message
log = Traceify("app", fmt=["timestamp", "message"])
log.warning("Something happened")
# → 2026-04-13 11:00:00  Something happened

✅ Runtime Format & Level Changes

log.set_format(["level", "message", "file"])   # change format on the fly
log.set_level("WARNING")                        # suppress DEBUG and INFO

✅ Log Level Filtering

Set a minimum level — messages below it are silently suppressed.

log = Traceify("auth", level="WARNING")  # only WARNING / ERROR / CRITICAL shown
log.debug("This won't appear")
log.warning("This will appear")

API Reference

Traceify(name, level, fmt)

Parameter Type Default Description
name str "root" Label shown in every log line
level str "DEBUG" Minimum log level to display
fmt list all fields Ordered list of fields to include

Logger methods

Method Description
log.debug(msg) Detailed diagnostic info
log.info(msg) General operational events
log.warning(msg) Unexpected but recoverable
log.error(msg) A serious problem
log.critical(msg) Fatal error
log.set_level(level) Change minimum level at runtime
log.set_format(fmt) Change field list at runtime

License

MIT

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

traceify-0.2.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

traceify-0.2.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file traceify-0.2.0.tar.gz.

File metadata

  • Download URL: traceify-0.2.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for traceify-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7ed27be76f1403408b73df2ae0866df5e1bd06b140b54d42e98370f21aaf26e0
MD5 6e116482950ee53b8da7ad206aebbce9
BLAKE2b-256 60a5a40ba0b0cdefc482df3f4753570a9a9790562e34dbd40059444fc40ea237

See more details on using hashes here.

File details

Details for the file traceify-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: traceify-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for traceify-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0233b2ed485539b3e8703b54b6b8f380f55af6f0d3e5b70fcb71a2862bce1c4b
MD5 0d4aa693c20379e6a904f42e23a86586
BLAKE2b-256 1ed3ef07eb7f095c6cdbc442bbfaf91bde2a50bb1bf7eb02bbd0cef7b1736748

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