Skip to main content

sclog - simple colorized log

Rationale

Python has a pretty convenient logging framework built-in, which makes it super easy to get started:

import logging

logging.warning("That was easy")

Or, if you have a few different files in your project and want to distinguish between them:

import logging

logger = logging.getLogger(__name__)

logger.error("Uh oh, something bad happened")

But, there are a few annoyances.

First, as the documentation explains, debug and info messages aren't shown with the default log level. Want to add a quick logging.debug message to your scripts? You'll need to configure a log formatter first.

Second, the default log formatting is missing some information like the timestamp. The default output looks something like this:

WARNING:root:your warning message

...and if you want it to look differently, you again need a custom formatter.

This library

This library exists, to be honest, for my own convenience. Its purpose it to provide some useful (to me) defaults as a very light-weight layer on top of Python's default logging framework. Specifically, it:

  1. Sets the default log level to DEBUG
  2. Uses a formatter that includes the timestamp
  3. (Optionally) colorizes the output using colorlog (another task that normally requires creating a custom formatter)

Usage

The "API" for this library is meant to be maximally compatible with the built-in logging API. Like Python's logging module, it exposes a getLogger function that you call with a string (the name). This returns a standard Logger object that you use in a familiar way.

from sclog import getLogger

logger = getLogger(__name__)

logger.info("Hello, %s!", "world")

This outputs (in a nice green color):

2021-01-01 00:00:00:00,000 - __main__ - DEBUG - Hello, world!

Installation

pip install sclog
pip install colorlog  # optional, include if you want colors

You can also just copy the file into your own project.

Metadata

Release files for sclog 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sclog 0.1.2
File Size Uploaded
sclog-0.1.2.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sclog 0.1.2
File Interpreter ABI Platform
sclog-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / sclog-0.1.2.tar.gz

Download URL sclog-0.1.2.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
15526b2c2263041cb72f586aee40c93dc73d1216190176f7f7ef2e2b45fcf7df
BLAKE2b-256 checksum
How to use checksums
d9c886284855d5c37c17358ca4ae0b4b8c05f39c8e87b80ee0edecad24883e35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.1 Darwin/18.7.0

Release files / sclog-0.1.2-py3-none-any.whl

Download URL sclog-0.1.2-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90fa18fad318e825808f7825241a07c6168605d9b37b77dfff8ea4bb66b6c94c
BLAKE2b-256 checksum
How to use checksums
1e83ff2d1f933537c29b054d48cea4c72f6094f56620981a712fd37d8c766e0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.1 Darwin/18.7.0

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page