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
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ pip install logurich[click]
## Usage

```python
import logging

from rich.panel import Panel

from logurich import init_logger
from logurich import get_logger, init_logger

init_logger("INFO", enqueue=False)

logger = logging.getLogger(__name__)
logger = get_logger(__name__)

logger.info("This is a log message")
logger.info("Hello %s", "world")
Expand Down Expand Up @@ -52,7 +50,9 @@ logger.info(

```

Named loggers returned by `logging.getLogger(...)` expose `ctx(...)`, `rich(...)`, `bind(...)`, and `contextualize(...)`. `logger.ctx(...)` is shorthand for the existing module-level `ctx(...)` helper, and `logger.contextualize(...)` is a convenience alias for `global_context_configure(...)`. The module-level helpers remain supported if you prefer `global_context_configure(...)` or `extra={"context": {"key": ctx(...)}}`.
For full IDE autocompletion of `ctx(...)`, `rich(...)`, `bind(...)`, and `contextualize(...)`, use `get_logger(...)` from logurich instead of `logging.getLogger(...)`. It returns the same logger instance but typed as `LogurichLogger`. `logger.ctx(...)` is shorthand for the existing module-level `ctx(...)` helper, and `logger.contextualize(...)` is a convenience alias for `global_context_configure(...)`. The module-level helpers remain supported if you prefer `global_context_configure(...)` or `extra={"context": {"key": ctx(...)}}`.

`logging.getLogger(...)` still works at runtime — only the typing differs.

For short-lived scripts and CLIs, `init_logger()` automatically registers an `atexit` hook, so you do not need to call `shutdown_logger()` just to flush logs at process exit.

Expand All @@ -61,17 +61,15 @@ For short-lived scripts and CLIs, `init_logger()` automatically registers an `at
Use the standard library to create named loggers:

```python
import logging

from logurich import init_logger
from logurich import get_logger, init_logger

init_logger("INFO", enqueue=False)

logger = logging.getLogger(__name__)
logger = get_logger(__name__)
logger.info("Hello from %s", __name__)
```

Logurich does not export a module-level logger or logger factory. Clients should create named loggers with `logging.getLogger(...)`.
Use `get_logger(...)` from logurich for typed access. `logging.getLogger(...)` still works at runtime.

## Using Logurich in Reusable Libraries

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "logurich"
version = "0.9.0"
version = "0.9.1"
description = "A Python library combining standard logging and Rich for beautiful logging."
authors = [
{ name = "PakitoSec", email = "jeromep83@gmail.com" }
Expand Down
4 changes: 3 additions & 1 deletion src/logurich/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Public package exports for logurich."""

__version__ = "0.9.0"
__version__ = "0.9.1"

from .console import (
console,
Expand All @@ -18,6 +18,7 @@
configure_child_logging,
ctx,
get_log_queue,
get_logger,
global_context_configure,
global_context_set,
init_logger,
Expand All @@ -42,4 +43,5 @@
"rich_to_str",
"LOG_LEVEL_CHOICES",
"LogLevel",
"get_logger",
]
13 changes: 12 additions & 1 deletion src/logurich/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,18 @@ def _install_logger_class() -> None:

_install_logger_class()

_internal_logger: LogurichLogger = logging.getLogger("logurich")

def get_logger(name: Optional[str] = None) -> LogurichLogger:
"""Typed wrapper around :func:`logging.getLogger`.

Returns the same logger instance but typed as :class:`LogurichLogger`
so that IDEs auto-complete ``ctx``, ``rich``, ``bind``, and
``contextualize``.
"""
return logging.getLogger(name) # type: ignore[return-value]


_internal_logger: LogurichLogger = get_logger("logurich")
_internal_logger.setLevel(logging.NOTSET)
_internal_logger.propagate = True

Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading