operations
Functions that can be imported and used to manage loguru.
add_sink(_logger=None, sink=None, level='INFO', format=default_fmt, color_format=default_color_fmt, filter=None, colorize=False, serialize=False, backtrace=False, diagnose=False, enqueue=False, catch=False, rotation=None, retention=None, compression=None)
Add a sink to a Loguru logger.
Helper function for adding a sink to a Loguru logger. Can be called without arguments to use a default instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_logger |
logger
|
An instance of |
None
|
sink |
str | Path | TextIOWrapper | Handler | Callable | Coroutine
|
A Loguru-compatible logger sink.
If the value is a |
None
|
level |
str
|
The all-caps log level for the sink, i.e. |
'INFO'
|
format |
str | Callable
|
The formatting for a log message |
default_fmt
|
color_formata |
str | Callable
|
The formatting for a colored log message |
required |
filter |
(str | Callable, dict)
|
A filter to control messages logged by Loguru |
None
|
colorize |
bool
|
If |
False
|
serialize |
bool
|
If |
False
|
backtrace |
bool
|
If |
False
|
diagnose |
bool
|
If |
False
|
enqueue |
bool
|
If using Loguru in an async context, |
False
|
catch |
bool
|
If |
False
|
rotation |
int | time | timedelta | str | Callable
|
Define log rotation rules for file logging |
None
|
retention |
int | timedelta | str | Callable
|
Define how long log files should be retained during rotation |
None
|
compression |
str | Callable
|
|
None
|
Source code in src/red_utils/ext/loguru_utils/operations.py
init_logger(sinks=[default_stderr_sink, default_app_log_file_sink, default_error_log_file_sink, default_trace_log_file_sink])
Initializes a Loguru logger using sink dicts.
Call this script very early in program execution, ideally as the very first thing to happen.
To ease with sink configuration, you can import sinks from red_utils.ext.loguru_utils.sinks,
like LoguruSinkStdOut which defines a default, colorized sys.stdout sink.
Note
If using a custom red_utils sink, when adding it to the list of sinks, use the .as_dict()
function to convert the sink to a dict.
Example:
``` py linenums="1"
stdout_sink = LoguruSinkStdOut(level="DEBUG")
init_logger(sinks=[stdout_sink.as_dict()])
```
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sinks |
list[dict]
|
A list of dicts defining Loguru sinks |
[default_stderr_sink, default_app_log_file_sink, default_error_log_file_sink, default_trace_log_file_sink]
|