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() → logging.Logger¶
If
context_logger
is set, return it.Otherwise, if
set_global_logger()
was called, return the global logger.Otherwise, return the pshell logger.
Using the pshell logger¶
- pshell.log.debug(msg, *args, **kwargs) → None¶
Wrapper around
logging.Logger.debug()
which uses the logger returned byget_logger()
.
- pshell.log.info(msg, *args, **kwargs) → None¶
Wrapper around
logging.Logger.info()
which uses the logger returned byget_logger()
.
- pshell.log.warning(msg, *args, **kwargs)¶
Wrapper around
logging.Logger.warning()
which uses the logger returned byget_logger()
.
- pshell.log.error(msg, *args, **kwargs) → None¶
Wrapper around
logging.Logger.error()
which uses the logger returned byget_logger()
.
- pshell.log.critical(msg, *args, **kwargs) → None¶
Wrapper around
logging.Logger.critical()
which uses the logger returned byget_logger()
.