Skip to main content

vcti-logging

Configurable logging with custom levels and color support for Python.

Overview

vcti-logging gives every script and service the same logging setup: the same levels, the same formats, the same behavior. It configures one package logger, vcti, from a list of handler descriptions — console, file, or both — each with its own level and message format, and replaces that configuration wholesale whenever it is called again. It adds two levels to Python's standard set, TRACE (5) and VERBOSE (15), with matching logger.trace() and logger.verbose() methods, optional colored console output, and named format presets so callers rarely write a %-style format string.


Installation

pip install vcti-logging

In requirements.txt

vcti-logging>=1.3.0

In pyproject.toml dependencies

dependencies = [
    "vcti-logging>=1.3.0",
]

Quick Start

from pathlib import Path

from vcti.logging import ConsoleLogConfig, FileLogConfig, logger, setup_logging

# Console logging with color
setup_logging([
    ConsoleLogConfig(log_level="trace", enable_color_log=True),
])

# Standard levels
logger.info("Application started")
logger.warning("Low disk space")

# Custom levels
logger.trace("Entering load() with path=%s", "model.h5")
logger.verbose("Processing item %d of %d", 3, 10)

# Reconfigure: console at INFO, everything from DEBUG up to a file
setup_logging([
    ConsoleLogConfig(log_level="info", enable_color_log=True),
    FileLogConfig(log_level="debug", file_path=Path("app.log")),
])

The same setup from keyword arguments, for callers that map command-line options straight through:

from vcti.logging import create_logging_config

setup_logging(create_logging_config(log_level="debug", log_file_path=Path("app.log")))

Log Levels

Name Value Purpose
"notset" 0 Pass every record
"trace" 5 Step-by-step execution detail
"debug" 10 Debug information
"verbose" 15 Detailed, but less noisy than DEBUG
"info" 20 General information (default)
"warning" 30 Warning conditions
"error" 40 Error conditions
"fatal" 50 Fatal errors

Configuration takes the names, case-insensitively. LogLevel is the matching IntEnum; decode_log_level() and encode_log_level() convert between the two.


Configuration

Message format presets

Preset Shows Use case
"minimal" message CLI tools, clean output
"standard" level + message General use (default)
"detailed" level + file + line + message Debugging

Each preset has a plain and a color variant; the right one is chosen from enable_color_log. Any other string is used as a raw format:

ConsoleLogConfig(log_level="debug", enable_color_log=True, message_format="detailed")
ConsoleLogConfig(message_format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

File logging

Files are written as UTF-8 and opened in append mode; mode="w" overwrites on each setup_logging() call. The parent directory must exist.

FileLogConfig(file_path=Path("app.log"), log_level="info", mode="w")

Console and file handlers are independent — each has its own level and preset, and file output never carries color codes:

setup_logging([
    ConsoleLogConfig(log_level="info", enable_color_log=True, message_format="standard"),
    FileLogConfig(log_level="debug", file_path=Path("app.log"), message_format="detailed"),
])

Child loggers

Modules log through children of vcti; their records reach the handlers configured above, with no setup of their own. get_logger() returns one, typed so that trace() and verbose() type-check:

from vcti.logging import get_logger

app_logger = get_logger("myapp")  # the "vcti.myapp" logger
app_logger.verbose("Application-specific message")

A name already under vcti is kept as is, so get_logger(__name__) works inside a vcti package.

Temporary configuration and tests

setup_logging() is for an application's entry point: it changes the process-wide vcti logger until the next call. Where a configuration must be undone — a test, a long-running host — use logging_configured(), which restores the previous handlers, level and propagation when the block exits, even if it raises:

from vcti.logging import logging_configured

with logging_configured([FileLogConfig(file_path=Path("run.log"), log_level="debug")]):
    logger.debug("written to run.log")
# the previous configuration is back, and run.log is closed

To log somewhere extra for a while — say, a log file for one job in a host that keeps its own console — use logging_added(). It attaches the handlers beside whatever is configured, replaces nothing, leaves propagation alone, and removes and closes them when the block exits:

from vcti.logging import logging_added

with logging_added([FileLogConfig(file_path=Path("job.log"), log_level="debug")]):
    logger.debug("in job.log only")
    logger.info("in job.log and wherever the host already logs")

If the file asks for records below what the logger lets through, the level is lowered for the block, and the handlers already in place are filtered so they still receive only what they did before. A setup_logging() or logging_configured() call inside the block leaves the added handlers working.

reset_logging() returns the logger to its import-time state: no handlers from this package, level NOTSET, propagation on. A test suite can call it after every test:

import pytest
from vcti.logging import reset_logging

@pytest.fixture(autouse=True)
def reset_vcti_logging():
    yield
    reset_logging()

All four manage only the handlers this package created; a handler attached by other code, such as pytest's log capture, is left in place.

Pydantic models

LogLevelCoder bundles the level type, default and valid names for a model field (requires pydantic, which this package does not depend on):

from pydantic import BaseModel, Field
from vcti.logging import LogLevelCoder

class AppConfig(BaseModel):
    log_level: LogLevelCoder.Literal = Field(
        default=LogLevelCoder.default,
        description=f"Supported: {'/'.join(LogLevelCoder.list)}",
    )

Public API

Symbol Purpose
setup_logging(configs, propagate=False) Replace the vcti logger's handlers
logging_configured(configs, propagate=False) Context manager: configure for a block, then restore
logging_added(configs) Context manager: add handlers beside the existing ones for a block
reset_logging() Return the vcti logger to its import-time state
ConsoleLogConfig / FileLogConfig Describe one console or file handler
create_logging_config(...) Build the config list from keyword arguments
logger / get_logger(name=None) The package logger, named "vcti" / it or a child, typed
CustomLevelLogger Logger class with trace() and verbose()
LogLevel / LogLevelStr Level enum / Literal of level names
decode_log_level(name) / encode_log_level(level) Name ↔ LogLevel
DEFAULT_LOG_LEVEL_STR / LOG_LEVEL_VALUES "info" / every level name
LogLevelCoder Level type, default, names and conversion in one object
MESSAGE_FORMAT_PRESETS / MessageFormatPreset Preset formats / preset names
resolve_message_format(fmt, color=False) Preset name or raw format → format string

Dependencies


Documentation

If you want to… Read
Get started using the package Quick Start above
Understand the design decisions and their trade-offs docs/design.md
Navigate and understand the source docs/source-guide.md
Contribute, run the checks or the benchmarks CONTRIBUTING.md

Metadata

Release files for vcti-logging 1.3.0

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

Source distribution (sdist)

Source distribution for vcti-logging 1.3.0
File Size Uploaded Provenance Actions
vcti_logging-1.3.0.tar.gz 34.4 kB With provenance Details for vcti_logging-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vcti-logging 1.3.0
File Interpreter ABI Platform Actions
vcti_logging-1.3.0-py3-none-any.whl Python 3 none any Details for vcti_logging-1.3.0-py3-none-any.whl

Total release size: 53.2 kB

Release files / vcti_logging-1.3.0.tar.gz

Download URL vcti_logging-1.3.0.tar.gz
Size 34.4 kB
Tags Source
SHA-256 checksum
How to use checksums
252c29f166606e8e6babfa1ed4c56270191913244c8fbcabc6b3e2a5a7f6b249
BLAKE2b-256 checksum
How to use checksums
3b978367bdfd9d32218d0b147269274f328d23ec3283703c57e94a2085b9263c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / vcti_logging-1.3.0-py3-none-any.whl

Download URL vcti_logging-1.3.0-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9f787b496ff8bec2aa324753f9569085c7cb61e13377f010b7de57b6de73688
BLAKE2b-256 checksum
How to use checksums
8bf09224de58aff30bf69f5a76aceb50b7ec23adb6c1933664013ec481d75972
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for vcti-logging 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vcti_logging-1.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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