Skip to content

msaUtils Module

.logger


Classes

InterceptHandler

Bases: logging.Handler

Default handler from examples in loguru documentaion. See https://loguru.readthedocs.io/en/stable/overview.html#entirely-compatible-with-standard-logging

Functions

emit
emit(record: logging.LogRecord)

Functions

format_record

format_record(record: dict) -> str

Custom format for loguru loggers. Uses pformat for log any data like request/response body during debug. Works with logging if loguru handler it.

Example
payload = [{"users":[{"name": "Nick", "age": 87, "is_active": True}, {"name": "Alex", "age": 27, "is_active": True}], "count": 2}]
logger.bind(payload=).debug("users payload")
[   {   'count': 2,
        'users': [   {'age': 87, 'is_active': True, 'name': 'Nick'},
                     {'age': 27, 'is_active': True, 'name': 'Alex'}]}]

init_logging

init_logging()

Replaces logging handlers with a handler for using the custom handler.

WARNING! if you call the init_logging in startup event function, then the first logs before the application start will be in the old format

Example
app.add_event_handler("startup", init_logging)

stdout:
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [11528] using statreload
INFO:     Started server process [6036]
INFO:     Waiting for application startup.

2020-07-25 02:19:21.357 | INFO     | uvicorn.lifespan.on:startup:34 - Application startup complete.

Last update: September 24, 2022
Created: September 24, 2022