Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
contents: read
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up uv
Expand All @@ -23,6 +23,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install deps
run: uv sync --group dev
- name: Run ruff
run: uv run ruff check src/logurich
- name: Run tests
run: uv run -m pytest -q

Expand Down
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,3 @@ repos:
hooks:
- id: ruff
- id: ruff-format
- repo: local
hooks:
- id: uv-pip-compile
name: uv pip compile (requirements.txt)
entry: uv
language: system
files: ^pyproject\.toml$
args: ["pip", "compile", "pyproject.toml", "-o", "requirements.txt"]
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Follow PEP 8 with four-space indentation and `snake_case` for functions, module-
Write tests with pytest and place them under `tests/`, naming files `test_<module>.py` and functions `test_<behaviour>`. Reuse shared fixtures from `tests/conftest.py`. Ensure new log formatting paths have representative assertions, and extend the example scripts when manual verification is useful. Run `uv run pytest` before opening a PR; aim to cover both the standard and rich rendering paths.

## Commit & Pull Request Guidelines
Commits follow Conventional Commit syntax (`type(scope): summary`) as seen in `git log`. Keep changes scoped and mention relevant modules in the scope. Pull requests must include a short summary, linked issues if applicable, and notes on testing (`uv run pytest`). Attach before/after screenshots or logs when changing console output. CI runs the test matrix across Python 3.9–3.13; wait for green builds before merging.
Commits follow Conventional Commit syntax (`type(scope): summary`) as seen in `git log`. Keep changes scoped and mention relevant modules in the scope. Pull requests must include a short summary, linked issues if applicable, and notes on testing (`uv run pytest`). Attach before/after screenshots or logs when changing console output. CI runs the test matrix across Python 3.10–3.13; wait for green builds before merging.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# logurich

[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![PyPI version](https://img.shields.io/pypi/v/logurich.svg)](https://pypi.org/project/logurich/)


A Python library combining Loguru and Rich for beautiful logging.
Expand Down Expand Up @@ -36,6 +37,12 @@ logger.rich(
title="Rich Panel",
prefix=False,
)

# Temporarily raise the minimum level
logger.level_set("WARNING")
logger.info("filtered")
logger.warning("visible")
logger.level_restore()
```

## Click CLI helper
Expand Down
21 changes: 16 additions & 5 deletions examples/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rich.panel import Panel
from rich.table import Table

from logurich import ctx, global_configure, init_logger, logger
from logurich import global_context_configure, init_logger, logger

logger.info("This is a basic log message")

Expand Down Expand Up @@ -31,20 +31,31 @@ def create_rich_table():
logger.rich("INFO", "[bold blue]This is a rich formatted log message[/bold blue]")

# Use context in logging
with global_configure(app=ctx("example", style="yellow")):
with global_context_configure(app=logger.ctx("example", style="yellow")):
logger.info("This log has app context")

with logger.contextualize(user=ctx("test", style="cyan", show_key=True)):
with logger.contextualize(user=logger.ctx("test", style="cyan", show_key=True)):
logger.info("ok")

# Log with additional context
logger.bind(environment=ctx("demo", style="yellow")).info(
logger.bind(environment=logger.ctx("demo", style="yellow")).info(
"This log has module context"
)

# Use logger.ctx() directly (no separate import needed)
logger.bind(session=logger.ctx("sess-42", style="cyan")).info(
"Using logger.ctx() instead of importing ctx"
)

# Temporarily raise the minimum level
logger.level_set("WARNING")
logger.info("filtered")
logger.warning("visible")
logger.level_restore()

# Log an exception
try:
1 / 0
1 / 0 # noqa: B018
except Exception as e:
logger.error("{}", e)
# logger.exception("An error occurred: {}", e)
Expand Down
20 changes: 11 additions & 9 deletions examples/mp_adv_data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
from rich.text import Text

from logurich import (
ctx,
global_configure,
global_set_context,
global_context_configure,
global_context_set,
init_logger,
logger,
mp_configure,
)


Expand Down Expand Up @@ -42,10 +40,10 @@ def process_item(item):
dict: The processed item result
"""
# Configure logurich for this process
mp_configure(logger)
logger.configure_child_logger(logger)

# Set context variables for this item
global_set_context(item=ctx(str(item["id"]), label="item", style="cyan"))
global_context_set(item=logger.ctx(str(item["id"]), label="item", style="cyan"))

try:
# Log the start of processing
Expand Down Expand Up @@ -105,11 +103,13 @@ def process_item(item):
def init_worker():
"""Initialize each worker process in the pool."""
# Configure logurich for this process
mp_configure(logger)
logger.configure_child_logger(logger)

# Add process-specific context
pid = os.getpid()
global_set_context(worker=ctx(f"Worker-{pid}", style="magenta", show_key=True))
global_context_set(
worker=logger.ctx(f"Worker-{pid}", style="magenta", show_key=True)
)

logger.info(f"Worker process {pid} initialized")

Expand All @@ -118,7 +118,9 @@ def main():
# Initialize the logger with rich handler
init_logger("INFO", log_verbose=2, rich_handler=False)

with global_configure(group=ctx("DataProcessor", style="green", show_key=True)):
with global_context_configure(
group=logger.ctx("DataProcessor", style="green", show_key=True)
):
logger.rich(
"INFO",
Panel("Starting parallel data processing example", border_style="blue"),
Expand Down
12 changes: 8 additions & 4 deletions examples/mp_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rich.panel import Panel
from rich.table import Table

from logurich import ctx, global_configure, init_logger, logger, mp_configure
from logurich import global_context_configure, init_logger, logger


def worker_function(worker_id):
Expand All @@ -14,10 +14,12 @@ def worker_function(worker_id):
Shows how to configure logurich in a child process.
"""
# Configure the logger in this process
mp_configure(logger)
logger.configure_child_logger(logger)

# Set a context variable for this worker
with global_configure(worker=ctx(f"Worker-{worker_id}", show_key=True)):
with global_context_configure(
worker=logger.ctx(f"Worker-{worker_id}", show_key=True)
):
# Log some basic messages
logger.info(f"Worker {worker_id} starting")
logger.debug(f"Worker {worker_id} debug message")
Expand Down Expand Up @@ -60,7 +62,9 @@ def main():
logger.info("Multiprocessing example starting")

# Create context for the main process
with global_configure(process=ctx("Main-Process", style="magenta", show_key=True)):
with global_context_configure(
process=logger.ctx("Main-Process", style="magenta", show_key=True)
):
# Create and start multiple worker processes
num_workers = 3
processes = []
Expand Down
30 changes: 0 additions & 30 deletions logurich/__init__.py

This file was deleted.

51 changes: 0 additions & 51 deletions logurich/__init__.pyi

This file was deleted.

20 changes: 0 additions & 20 deletions logurich/core.pyi

This file was deleted.

Loading