Handlers¶
The package currently ships with console and file logging handlers.
Console handler¶
build_console_handler(formatter) returns a standard logging.StreamHandler configured with the provided formatter.
File handler¶
build_file_handler(config, formatter) returns a rotating file handler.
config.file_pathis requiredconfig.file_max_bytescontrols rotation sizeconfig.file_backup_countcontrols retained backups
Handler order¶
build_handlers(config, formatter) preserves the order from config.handlers.
from fastapi_inspector import ObserverConfig
from fastapi_inspector.handlers import build_handlers
from fastapi_inspector.formatters import JsonFormatter
config = ObserverConfig(handlers=["file", "console"], file_path="logs/api.log")
handlers = build_handlers(config, JsonFormatter())