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
2 changes: 1 addition & 1 deletion .github/workflows/1.bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.10"
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install -U pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/2.build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.10"
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install -U pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.10"
python-version: "3.11"
- name: Cache pip
uses: actions/cache@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.10"
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install -U pip
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fail_fast: true
default_language_version:
python: python3.10
python: python3.11
exclude: |
(?x)^(
\.git/.*
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.10
3.11
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]
dynamic = ["version", "dependencies", "optional-dependencies"]

Expand Down
20 changes: 8 additions & 12 deletions src/beans_logging/filters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from loguru import Record

from .typing import Record
from .constants import (
DEFAULT_STD_HANDLER_NAME,
DEFAULT_FILE_HANDLER_NAME,
Expand All @@ -12,7 +8,7 @@
)


def add_level_short(record: "Record") -> "Record":
def add_level_short(record: Record) -> Record:
"""Filter for adding short level name to log record.

Args:
Expand All @@ -37,7 +33,7 @@ def add_level_short(record: "Record") -> "Record":
return record


def all_handlers_filter(record: "Record") -> bool:
def all_handlers_filter(record: Record) -> bool:
"""Filter message for all handlers that use this filter.

Args:
Expand All @@ -55,7 +51,7 @@ def all_handlers_filter(record: "Record") -> bool:
return True


def std_filter(record: "Record") -> bool:
def std_filter(record: Record) -> bool:
"""Filter message for std handlers that use this filter.

Args:
Expand All @@ -74,7 +70,7 @@ def std_filter(record: "Record") -> bool:
return True


def file_filter(record: "Record") -> bool:
def file_filter(record: Record) -> bool:
"""Filter message for file handlers that use this filter.

Args:
Expand All @@ -93,7 +89,7 @@ def file_filter(record: "Record") -> bool:
return True


def err_file_filter(record: "Record") -> bool:
def err_file_filter(record: Record) -> bool:
"""Filter message for error file handlers that use this filter.

Args:
Expand All @@ -112,7 +108,7 @@ def err_file_filter(record: "Record") -> bool:
return True


def json_filter(record: "Record") -> bool:
def json_filter(record: Record) -> bool:
"""Filter message for json file handlers that use this filter.

Args:
Expand All @@ -131,7 +127,7 @@ def json_filter(record: "Record") -> bool:
return True


def err_json_filter(record: "Record") -> bool:
def err_json_filter(record: Record) -> bool:
"""Filter message for json error file handlers that use this filter.

Args:
Expand Down
6 changes: 2 additions & 4 deletions src/beans_logging/formats.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import json
import traceback
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from loguru import Record
from .typing import Record


def json_format(record: "Record") -> str:
def json_format(record: Record) -> str:
"""Custom json formatter for loguru logger.

Args:
Expand Down
7 changes: 3 additions & 4 deletions src/beans_logging/rotators.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import datetime
from typing import TextIO, TYPE_CHECKING
from typing import TextIO

if TYPE_CHECKING:
from loguru import Message
from .typing import Message


class Rotator:
Expand Down Expand Up @@ -38,7 +37,7 @@ def __init__(self, *, rotate_size: int, rotate_time: datetime.time):
# Add one day to prevent an immediate rotation.
self._dt_limit += datetime.timedelta(days=1)

def should_rotate(self, message: "Message", file: TextIO) -> bool:
def should_rotate(self, message: Message, file: TextIO) -> bool:
"""Check if the log file should rotate.

Args:
Expand Down
16 changes: 5 additions & 11 deletions src/beans_logging/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@
from logging import Handler
from asyncio import AbstractEventLoop
from multiprocessing.context import BaseContext
from typing import TYPE_CHECKING, Any, TextIO, Union, Protocol, runtime_checkable
from typing import Any, TextIO, Union, Protocol, runtime_checkable
from collections.abc import Callable, Awaitable

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

if TYPE_CHECKING:
from loguru import Record, Message
else:
from .typing import Record, Message

from pydantic import BaseModel, Field, ConfigDict, model_validator

from .typing import Record, Message
from .constants import LogHandlerTypeEnum, LogLevelEnum


Expand Down Expand Up @@ -52,12 +48,10 @@ def flush(self) -> Any: ...
Handler,
]

FormatType = Union[
str, Callable[["Record"], str], Callable[[dict[str, Any]], str], None
]
FormatType = Union[str, Callable[[Record], str], Callable[[dict[str, Any]], str], None]

_FilterType = Union[
Callable[["Record"], bool],
Callable[[Record], bool],
Callable[[dict[str, Any]], bool],
str,
dict[str, Any],
Expand All @@ -69,7 +63,7 @@ def flush(self) -> Any: ...
int,
datetime.time,
datetime.timedelta,
Callable[["Message", TextIO], bool],
Callable[[Message, TextIO], bool],
Callable[[str, TextIO], bool],
Callable[[str, Any], bool],
None,
Expand Down
6 changes: 2 additions & 4 deletions src/beans_logging/sinks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import sys
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from loguru import Message
from .typing import Message


def std_sink(message: "Message") -> None:
def std_sink(message: Message) -> None:
"""Print message based on log level to stdout or stderr.

Args:
Expand Down