academy.logging¶
JSONHandler
¶
JSONHandler(filename: Path)
Bases: Handler
A LogHandler which outputs records as JSON objects, one per line.
Source code in academy/logging.py
emit
¶
emit(record: LogRecord) -> None
Emits the log record as a JSON object.
Each attribute (including extra attributes) of the log record becomes
an entry in the JSON object. Each value is rendered using str.
Source code in academy/logging.py
init_logging
¶
init_logging(
level: int | str = INFO,
*,
logfile: str | Path | None = None,
logfile_level: int | str | None = None,
color: bool = True,
extra: int = False,
force: bool = False
) -> Logger
Initialize global logger.
Parameters:
-
level(int | str, default:INFO) –Minimum logging level.
-
logfile(str | Path | None, default:None) –Configure a file handler for this path.
-
logfile_level(int | str | None, default:None) –Minimum logging level for the file handler. Defaults to that of
level. -
color(bool, default:True) –Use colorful logging for stdout.
-
extra(int, default:False) –Include extra info in log messages, such as thread ID and process ID. This is helpful for debugging. True or 1 adds some extra info. 2 adds on observability-style logging of key-value metadata, and adds a second logfile formatted as JSON.
-
force(bool, default:False) –Remove any existing handlers attached to the root handler. This option is useful to silencing the third-party package logging. Note: should not be set when running inside pytest.
Returns:
-
Logger–The root logger.
Source code in academy/logging.py
execute_and_log_traceback
async
¶
Await a future and log any exception..
Catches any exceptions raised by the coroutine, logs the traceback, and re-raises the exception.