logging
¶
Helpers for logging.
LoggingLevels
¶
Bases: CustomStrEnum
A class holding the valid logging levels supported.
CRITICAL
class-attribute
instance-attribute
¶
CRITICAL = 'CRITICAL'
An enum member representing the CRITICAL logging level.
DEBUG
class-attribute
instance-attribute
¶
DEBUG = 'DEBUG'
An enum member representing the DEBUG logging level.
ERROR
class-attribute
instance-attribute
¶
ERROR = 'ERROR'
An enum member representing the ERROR logging level.
INFO
class-attribute
instance-attribute
¶
INFO = 'INFO'
An enum member representing the INFO logging level.
NONE
class-attribute
instance-attribute
¶
NONE = 'NONE'
An enum member indicating no logging messages should be captured.
WARNING
class-attribute
instance-attribute
¶
WARNING = 'WARNING'
An enum member representing the WARNING logging level.
configure_logging
¶
configure_logging(
*,
log_console_level: str | LoggingLevels = INFO,
log_file_level: str | LoggingLevels = DEBUG,
log_file_directory: str | PathLike[str] | Path | None = None,
log_file_name: str | None = None,
log_colored_output: bool = False,
log_pyvisa_messages: bool = False,
log_uncaught_exceptions: bool = True
) -> Logger
Configure the logging for this package.
Note
After this function is called once, if it is called again, it will not perform any additional configuration. It will simply return the base logger for the package. This means that if logging is configured explicitly in Python code, then any configuration options set in the config file or environment variables will be ignored.
Important
This function will overwrite the sys.excepthook function in order to
log uncaught exceptions if logging to a log file is enabled. The custom hook function
used by this package will call sys.__excepthook__ after the custom
code is run, so exceptions and tracebacks will still get printed to the console. If you
have a custom exception hook function you need to use, you will need to overwrite the
sys.excepthook function after this package’s logging is configured.
To opt out of this behavior and keep Python’s default exception handling
(which means exceptions will not be logged to the log file), set the
log_uncaught_exceptions parameter to False.
| Parameters: |
|
|---|
| Returns: |
|
|---|
disable_all_loggers
¶
disable_all_loggers(
level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "CRITICAL",
) -> Generator[None, None, None]
Temporarily disable all logging calls of severity ‘level’ and below within this context.
Examples:
>>> with disable_all_loggers():
... logging.info("This is inside the context and will not be logged")
>>> logging.info("This is outside the context and will be logged")
>>> with disable_all_loggers(level="WARNING"):
... logging.info("This will not be logged")
... logging.warning("This will not be logged")
... logging.error("This will be logged since its level is above WARNING")
| Parameters: |
|
|---|