Metadata-Version: 2.4
Name: vcti-logging
Version: 1.1.0
Summary: Configurable logging with custom levels and color support for Python
Author: Visual Collaboration Technologies Inc.
License-Expression: LicenseRef-Proprietary
Project-URL: Repository, https://github.com/vcollab/vcti-python-logging
Project-URL: Changelog, https://github.com/vcollab/vcti-python-logging/blob/main/CHANGELOG.md
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <3.15,>=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: colorlog
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Provides-Extra: lint
Requires-Dist: ruff; extra == "lint"
Provides-Extra: typecheck
Requires-Dist: mypy; extra == "typecheck"
Provides-Extra: bench
Requires-Dist: tabulate; extra == "bench"
Dynamic: license-file

# 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

```bash
pip install vcti-logging
```

### In `requirements.txt`

```
vcti-logging>=1.1.0
```

### In `pyproject.toml` dependencies

```toml
dependencies = [
    "vcti-logging>=1.1.0",
]
```

---

## Quick Start

```python
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:

```python
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:

```python
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.

```python
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:

```python
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:

```python
import logging

app_logger = logging.getLogger("vcti.myapp")
app_logger.verbose("Application-specific message")
```

Import `vcti.logging` before creating them: loggers created earlier lack
`trace()` and `verbose()`.

### Pydantic models

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

```py
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 |
| `ConsoleLogConfig` / `FileLogConfig` | Describe one console or file handler |
| `create_logging_config(...)` | Build the config list from keyword arguments |
| `logger` | The package logger, named `"vcti"` |
| `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

- [`colorlog`](https://pypi.org/project/colorlog/) — colored console
  output.

---

## 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](docs/design.md) |
| Navigate and understand the source | [docs/source-guide.md](docs/source-guide.md) |
| Contribute, run the checks or the benchmarks | [CONTRIBUTING.md](CONTRIBUTING.md) |
