srctools.logger
Wrapper around logging to provide our own functionality.
This adds the ability to log using str.format() instead of %.
- class srctools.logger.LoggerAdapter( )
Fix loggers to use str.format().
- log(
- level: int,
- msg: Any,
- *args: Any,
- exc_info: None | bool | Tuple[Type[BaseException], BaseException, TracebackType | None] | Tuple[None, None, None] | BaseException = None,
- stack_info: bool = False,
- extra: Mapping[str, object] | None = None,
- stacklevel: int = 0,
- **kwargs: Any,
This version of
log()
is forstr.format()
compatibility.The message is wrapped in a
LogMessage
object, which is given theargs
andkwargs
.
- srctools.logger.get_handler( ) FileHandler
Cycle log files, then give the required file handler.
- srctools.logger.get_logger( ) Logger
Get the named logger object.
This puts the logger into the
srctools
namespace, and wraps it to usestr.format()
instead of%
formatting. If set,alias
is the name to show for the module.
- srctools.logger.init_logging(
- filename: StringPath | None = None,
- main_logger: str = '',
- on_error: Callable[[Type[BaseException], BaseException, TracebackType | None], None] | None = None,
- srctools.logger.init_logging(
- filename: StringPath | None = None,
- main_logger: str = '',
- *,
- error: Callable[[BaseException], object],
Set up the logger and logging handlers.
This also sets
sys.excepthook()
, so uncaught exceptions are captured.If an unhandled
BaseException
is raised, this will not log or call the callback.- Parameters:
filename – If this is set, all logs will be written to this file as well.
error – should be a function to call when uncaught exceptions are thrown.
on_error – Deprecated version of
error
with the old-style exception tuple representation from Python 3.10 and below.main_logger – Specify the name of the logger to produce under the srctools hierachy.