Logging

pshell uses logging to record all commands to the stderr or log file. By default, it uses the pshell logger; it can however be set to use an alternative, possibly context-local, logger.

Setting and retrieving the pshell logger

pshell.set_global_logger(logger: Logger | str | None) Logger | None

Set the pshell global logger. This logger will be used by all pshell functions unless context_logger is defined.

Returns:

Previous global logger

pshell.context_logger = <ContextVar name='context_logger' default=None>

ContextVar. Context-local logger, for use in multithreaded and asynchronous code. This is not inherited when creating a new thread. See contextvars for more information on how context variables propagate. Set to None to use the global logger instead.

pshell.get_logger() Logger
  1. If context_logger is set, return it.

  2. Otherwise, if set_global_logger() was called, return the global logger.

  3. Otherwise, return the pshell logger.

Using the pshell logger

pshell.log.debug(msg: str, *args: Any, **kwargs: Any) None

Wrapper around logging.Logger.debug() which uses the logger returned by get_logger().

pshell.log.info(msg: str, *args: Any, **kwargs: Any) None

Wrapper around logging.Logger.info() which uses the logger returned by get_logger().

pshell.log.warning(msg: str, *args: Any, **kwargs: Any) None

Wrapper around logging.Logger.warning() which uses the logger returned by get_logger().

pshell.log.error(msg: str, *args: Any, **kwargs: Any) None

Wrapper around logging.Logger.error() which uses the logger returned by get_logger().

pshell.log.critical(msg: str, *args: Any, **kwargs: Any) None

Wrapper around logging.Logger.critical() which uses the logger returned by get_logger().