logger¶
Here's the reference for the logging utilities.
You can import them directly from fastapi_toolsets.logger:
fastapi_toolsets.logger.configure_logging(level='INFO', fmt=DEFAULT_FORMAT, logger_name=None)
¶
Configure logging with a stdout handler and consistent format.
Sets up a :class:~logging.StreamHandler writing to stdout with the
given format and level. Also configures the uvicorn loggers so that
FastAPI access logs use the same format.
Calling this function multiple times is safe -- existing handlers are replaced rather than duplicated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
LogLevel | int
|
Log level (e.g. |
'INFO'
|
fmt
|
str
|
Log format string. Defaults to
|
DEFAULT_FORMAT
|
logger_name
|
str | None
|
Logger name to configure. |
None
|
Returns:
| Type | Description |
|---|---|
Logger
|
The configured Logger instance. |
fastapi_toolsets.logger.get_logger(name=_SENTINEL)
¶
Return a logger with the given name.
A thin convenience wrapper around :func:logging.getLogger that keeps
logging imports consistent across the codebase.
When called without arguments, the caller's __name__ is used
automatically, so get_logger() in a module is equivalent to
logging.getLogger(__name__). Pass None explicitly to get the
root logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Logger name. Defaults to the caller's |
_SENTINEL
|
Returns:
| Type | Description |
|---|---|
Logger
|
A Logger instance. |