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,) None
msg: Any,
*args: Any,
exc_info: Union[None, bool, Tuple[type, BaseException, Optional[TracebackType]], Tuple[None, None, None], BaseException] = None,
stack_info: bool = False,
extra: Optional[Mapping[str, object]] = None,
**kwargs: Any, This version of
log()
is forstr.format()
compatibility.The message is wrapped in a
LogMessage
object, which is given theargs
andkwargs
.stacklevel
is supported, but is silently ignored in Python 3.7.
-
-
srctools.logger.
get_handler
(filename: str | os.PathLike[str]) 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: Optional[StringPath] = None,) Logger
main_logger: str = '',
on_error: Optional[Callable[[Type[BaseException], BaseException, Optional[TracebackType]], None]] = None, -
srctools.logger.
init_logging
() Logger 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.