A logger producing O from each entry. Make one with
Logger.make; install it with logger.layer([...]) or
eff.with_logger(...).
Functions#
__init__#
__init__(log) -> None| Parameter | Type | Description |
|---|---|---|
log | Callable[[Options], O_co] |
def __init__(self, log: Callable[[Options], O_co]) -> None:
self._log = logmake#
make(log) -> Logger[O]| Parameter | Type | Description |
|---|---|---|
log | Callable[[Options], O] |
Returns Logger[O]
@staticmethod
def make[O](log: Callable[[Options], O]) -> Logger[O]:
return Logger(log)log#
log(options) -> O_co| Parameter | Type | Description |
|---|---|---|
options | Options |
Returns O_co
def log(self, options: Options) -> O_co:
return self._log(options)map#
map(f) -> Logger[O2]A logger whose output is f of this one's.
| Parameter | Type | Description |
|---|---|---|
f | Callable[[O_co], O2] |
Returns Logger[O2]
def map[O2](self, f: Callable[[O_co], O2]) -> Logger[O2]:
"""A logger whose output is ``f`` of this one's."""
log = self._log
return Logger(lambda options: f(log(options)))with_console_log#
with_console_log() -> Logger[None]Write the output to the current console with log.
Returns Logger[None]
def with_console_log(self) -> Logger[None]:
"""Write the output to the current console with ``log``."""
return self._to_console(lambda console, _level: console.log)with_console_error#
with_console_error() -> Logger[None]Write the output to the current console with error.
Returns Logger[None]
def with_console_error(self) -> Logger[None]:
"""Write the output to the current console with ``error``."""
return self._to_console(lambda console, _level: console.error)with_leveled_console#
with_leveled_console() -> Logger[None]Write the output with the console method matching the level:
debug, info, trace, warn, error (for ERROR
and FATAL).
Returns Logger[None]
def with_leveled_console(self) -> Logger[None]:
"""Write the output with the console method matching the level:
``debug``, ``info``, ``trace``, ``warn``, ``error`` (for ``ERROR``
and ``FATAL``)."""
def method(console: Console, level: LogLevel) -> Callable[..., None]:
match level:
case LogLevel.DEBUG:
return console.debug
case LogLevel.INFO:
return console.info
case LogLevel.TRACE:
return console.trace
case LogLevel.WARN:
return console.warn
case LogLevel.ERROR | LogLevel.FATAL:
return console.error
case _:
return console.log
return self._to_console(method)batched#
batched(*, window, flush) -> Effect[Logger[None], Never, Scope]A logger that buffers this one's outputs and hands them to
flush every window, and once more when the scope closes
(after any flush in progress).
| Parameter | Type | Description |
|---|---|---|
window | Duration | |
flush | Callable[[Sequence[O_co]], Effect[object]] |
Returns Effect[Logger[None], Never, Scope]
def batched(
self, *, window: Duration, flush: Callable[[Sequence[O_co]], Effect[object]]
) -> Effect[Logger[None], Never, Scope]:
"""A logger that buffers this one's outputs and hands them to
``flush`` every ``window``, and once more when the scope closes
(after any flush in progress)."""
from pyfect.logger._batched import batched
return batched(self, window, flush)pipe#
pipe(f) -> B| Parameter | Type | Description |
|---|---|---|
f | Callable[[Self], B] |
Returns B
def pipe[B](self, f: Callable[[Self], B], /) -> B:
return f(self)