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