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: bool | tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None] | BaseException | None = 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
LogMessageobject, which is given theargsandkwargs.
- 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
srctoolsnamespace, and wraps it to usestr.format()instead of%formatting. If set,aliasis 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
BaseExceptionis 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
errorwith 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.