This module provides functions for logging messages with a "Safe Init" prefix.
get_logger()
Get the logger instance to use throughout the code.
| Returns: |
|
|---|
Source code in safe_init/safe_logging.py
def get_logger() -> "BoundLogger":
"""
Get the logger instance to use throughout the code.
Returns:
The logger instance.
"""
ctx_logger = get_contextvar_named("safe_init_logger_getter")
if not ctx_logger:
return _get_structlog_logger()
return ctx_logger()
log_debug(*args, **kwargs)
Logs a debug message with the "Safe Init" prefix.
Source code in safe_init/safe_logging.py
def log_debug(*args: Any, **kwargs: Any) -> None: # noqa: ANN401
"""
Logs a debug message with the "Safe Init" prefix.
"""
if not bool_env("SAFE_INIT_DEBUG"):
return
get_logger().info(*_add_prefix(args), **kwargs)
log_error(*args, **kwargs)
Logs an error message with the "Safe Init" prefix.
Source code in safe_init/safe_logging.py
def log_error(*args: Any, **kwargs: Any) -> None: # noqa: ANN401
"""
Logs an error message with the "Safe Init" prefix.
"""
get_logger().error(*_add_prefix(args), **kwargs)
log_exception(*args, **kwargs)
Logs an error message with the "Safe Init" prefix and exception traceback.
Source code in safe_init/safe_logging.py
def log_exception(*args: Any, **kwargs: Any) -> None: # noqa: ANN401
"""
Logs an error message with the "Safe Init" prefix and exception traceback.
"""
get_logger().exception(*_add_prefix(args), **kwargs)
log_info(*args, **kwargs)
Logs a info message with the "Safe Init" prefix.
Source code in safe_init/safe_logging.py
def log_info(*args: Any, **kwargs: Any) -> None: # noqa: ANN401
"""
Logs a info message with the "Safe Init" prefix.
"""
get_logger().info(*_add_prefix(args), **kwargs)
log_warning(*args, **kwargs)
Logs a warning message with the "Safe Init" prefix.
Source code in safe_init/safe_logging.py
def log_warning(*args: Any, **kwargs: Any) -> None: # noqa: ANN401
"""
Logs a warning message with the "Safe Init" prefix.
"""
get_logger().warning(*_add_prefix(args), **kwargs)