Skip to main content

Lightweight colored console logging with zero dependencies.

Project description

xlog

Lightweight colored console logging for Python. Zero dependencies, pure stdlib.

pip install sklog

Why xlog

Python's built-in logging module is powerful but verbose to configure for simple scripts and CLI tools. xlog gives you colored, leveled output in one import with no setup.


Quick start

from sklog import xlog_info, xlog_warning, xlog_error, xlog_success, xlog_debug

xlog_info("Server started on port 8080")
xlog_warning("Disk usage above 80 percent")
xlog_error("Database connection refused")
xlog_success("Deployment finished")
xlog_debug("Cache miss for key user:42")

Terminal output:

[*] Server started on port 8080
[!] Disk usage above 80 percent
[#] Database connection refused
[^] Deployment finished
[?] Cache miss for key user:42

Each level prints in its own color — blue, yellow, red, green, magenta.


All functions

Typed wrappers

The easiest way to log. Each function maps to a fixed level.

xlog_info("Listening on port 8080")         # blue    [*]
xlog_warning("Retrying in 5 seconds")       # yellow  [!]
xlog_error("Permission denied")             # red     [#]  → writes to stderr
xlog_success("All tests passed")            # green   [^]
xlog_debug("payload = {'id': 42}")          # magenta [?]

All wrappers accept two keyword arguments:

xlog_success("Deployed", timestamp=True)    # prepend HH:MM:SS
xlog_error("Crashed", timestamp=True)

Generic function

When you want to pick the level dynamically:

from sklog import xlog

xlog("Starting up")              # default, white
xlog("Watch this", "w")         # warning
xlog("Done", "s", bold=True)    # success, bold
xlog("Trace", "d", timestamp=True, bold=True)

Full signature:

xlog(msg, flag=None, *, timestamp=False, bold=False, file=sys.stdout)
flag level color symbol
"d" DEBUG magenta [?]
"e" ERROR red [#]
"w" WARNING yellow [!]
"s" SUCCESS green [^]
"n" INFO blue [*]
None DEFAULT white [ ]

Unknown flags fall back to DEFAULT silently rather than raising.

Formatting helpers

from sklog import xlog_header, xlog_separator

xlog_header("Build Report")          # bold + underlined, blank lines above and below
xlog_separator()                     # cyan === line, 50 chars wide
xlog_separator("-", 30)             # custom char and width

Options

timestamp=True

Prepends the current time in HH:MM:SS format:

xlog_success("Build passed", timestamp=True)
# [14:32:07] [^] Build passed

xlog_error("Timeout", timestamp=True)
# [14:32:09] [#] Timeout

bold=True

Makes the symbol and message text bold. Only available on xlog directly:

xlog("Critical section complete", "s", bold=True)

file=

Redirect output to any writable stream. Useful in tests or when writing logs to a file alongside printing:

import sys
xlog_warning("Low memory", file=sys.stderr)

with open("run.log", "w") as f:
    xlog_info("Started", file=f)

xlog_error defaults to sys.stderr. All other functions default to sys.stdout.


Real-world example

from sklog import xlog_header, xlog_info, xlog_success, xlog_error, xlog_separator

def deploy(service: str) -> None:
    xlog_header(f"Deploying {service}")

    xlog_info("Pulling latest image", timestamp=True)
    xlog_info("Running migrations", timestamp=True)

    ok = run_migrations()

    if ok:
        xlog_success("Migrations applied", timestamp=True)
        xlog_success(f"{service} is live")
    else:
        xlog_error("Migration failed — rolling back", timestamp=True)

    xlog_separator()

Output:


Deploying api-service

[14:05:01] [*] Pulling latest image
[14:05:02] [*] Running migrations
[14:05:04] [^] Migrations applied
[^] api-service is live
==================================================

Requirements

  • Python 3.8 or newer
  • No third-party dependencies

Development

git clone https://github.com/shahil-sk/sklog
cd sklog
pip install -e ".[dev]"
pytest -v

License

MIT — see LICENSE.

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

sklog-2.0.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

sklog-2.0.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file sklog-2.0.1.tar.gz.

File metadata

  • Download URL: sklog-2.0.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for sklog-2.0.1.tar.gz
Algorithm Hash digest
SHA256 597b68323b80381c55ce780dab48ccd534a4b776485fa64da40f424c540ea9e5
MD5 31034455d335e6e5086e7f08b20b5c42
BLAKE2b-256 c17b3db5d89b021fad8ee9bd3d49ed82c3fb7d3591c3a2021e68d0ed42c36bc4

See more details on using hashes here.

File details

Details for the file sklog-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: sklog-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for sklog-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d33536be17fb1f209deb43d38f2d4dc08d31de5eb1265fa6daa7652554cfe8b4
MD5 0fce09654f4c716f57a42bd1096e7337
BLAKE2b-256 968c84bc702ab501ec38d39e250e923f9b829a5d37d21e52738beca4c4a6dab3

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