Skip to main content

Lightweight colored console logging with zero dependencies.

Project description

sklog

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

pip install sklog

Why sklog

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.2.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.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sklog-2.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 5bacdfb940e49675833b332245ea6a6220706612398751a82fa58b0d78466ee6
MD5 22c14668db4334328e0adf54fe71e586
BLAKE2b-256 3018608669b62dee6b1e716b1488001ef46e3b0fa36c88c995db247dc4812f8a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sklog-2.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2e7bd8c691288d8b0bd393b28c70e5ef7758c266b55059b86a4e941b5d1fc3d6
MD5 b2969a853e0c61ae13200f345a310e68
BLAKE2b-256 c25157b221cd89a605b185f29b62b9ef2a0dd7d2d713edba12d93146ce392c30

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