main commit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-16 16:30:25 +09:00
parent 91c7e04474
commit 537e7b363f
1146 changed files with 45926 additions and 77196 deletions

View File

@@ -17,6 +17,8 @@ from pickle import PicklingError
from sys import stderr, stdout
from typing import IO, Any, BinaryIO, TextIO
from structlog._utils import until_not_interrupted
WRITE_LOCKS: dict[IO[Any], threading.Lock] = {}
@@ -34,7 +36,8 @@ class PrintLogger:
"""
Print events into a file.
Args:
Arguments:
file: File to print to. (default: `sys.stdout`)
>>> from structlog import PrintLogger
@@ -107,7 +110,7 @@ class PrintLogger:
"""
f = self._file if self._file is not stdout else None
with self._lock:
print(message, file=f, flush=True)
until_not_interrupted(print, message, file=f, flush=True)
log = debug = info = warn = warning = msg
fatal = failure = err = error = critical = exception = msg
@@ -119,7 +122,8 @@ class PrintLoggerFactory:
To be used with `structlog.configure`\ 's ``logger_factory``.
Args:
Arguments:
file: File to print to. (default: `sys.stdout`)
Positional arguments are silently ignored.
@@ -138,7 +142,8 @@ class WriteLogger:
"""
Write events into a file.
Args:
Arguments:
file: File to print to. (default: `sys.stdout`)
>>> from structlog import WriteLogger
@@ -214,8 +219,8 @@ class WriteLogger:
Write and flush *message*.
"""
with self._lock:
self._write(message + "\n")
self._flush()
until_not_interrupted(self._write, message + "\n")
until_not_interrupted(self._flush)
log = debug = info = warn = warning = msg
fatal = failure = err = error = critical = exception = msg
@@ -227,7 +232,8 @@ class WriteLoggerFactory:
To be used with `structlog.configure`\ 's ``logger_factory``.
Args:
Arguments:
file: File to print to. (default: `sys.stdout`)
Positional arguments are silently ignored.
@@ -246,7 +252,7 @@ class BytesLogger:
r"""
Writes bytes into a file.
Args:
Arguments:
file: File to print to. (default: `sys.stdout`\ ``.buffer``)
Useful if you follow `current logging best practices
@@ -255,8 +261,7 @@ class BytesLogger:
.. versionadded:: 20.2.0
"""
__slots__ = ("_file", "_flush", "_lock", "_write")
__slots__ = ("_file", "_write", "_flush", "_lock")
def __init__(self, file: BinaryIO | None = None):
self._file = file or sys.stdout.buffer
@@ -318,8 +323,8 @@ class BytesLogger:
Write *message*.
"""
with self._lock:
self._write(message + b"\n")
self._flush()
until_not_interrupted(self._write, message + b"\n")
until_not_interrupted(self._flush)
log = debug = info = warn = warning = msg
fatal = failure = err = error = critical = exception = msg
@@ -331,14 +336,14 @@ class BytesLoggerFactory:
To be used with `structlog.configure`\ 's ``logger_factory``.
Args:
Arguments:
file: File to print to. (default: `sys.stdout`\ ``.buffer``)
Positional arguments are silently ignored.
.. versionadded:: 20.2.0
"""
__slots__ = ("_file",)
def __init__(self, file: BinaryIO | None = None):