neclib.core.inform.console_logger#
- class ColorizeLevelNameFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#
Bases:
Formatter
Colorize severity level name.
See logging docs for the usage.
- ColorPrefix: Dict[int, str] = {0: '\x1b[0m', 10: '\x1b[35m', 20: '\x1b[32m', 30: '\x1b[33m', 40: '\x1b[31m', 50: '\x1b[41;97m'}#
- class Throttle(*args, **kwargs)[source]#
Bases:
Filter
Reduce logging frequency of identical messages.
- Parameters:
duration_sec – Duration in seconds. If the same message is logged within this duration, attached handlers discard it.
- get_logger(name=None, min_level=None, throttle_duration_sec=1.0)[source]#
Get logger instance which prints operation logs to console.
- Parameters:
name (Optional[str]) – Name of the logger. Calling this function with same
name
returns the same logger instance.min_level (Optional[int]) – Lower bound of severity level to be displayed on terminal. To suppress less severe messages, set higher value. No matter this value, the log file contains all messages severer than
logging.INFO
(level=20).throttle_duration_sec (Union[int, float]) – Duration in seconds to throttle messages. If the same message is logged within this duration, the message is not displayed on terminal.
- Return type:
Logger
Examples
>>> logger = neclib.interfaces.getLogger("OTF_observation", "path/to/log.txt") >>> logger.debug("Inform something only needed on diagnosing some problem.") >>> logger.info("Inform something EXPECTED has happened.") >>> logger.warning("Inform something user should care has happened.") >>> logger.error(f"Notify some {functionality} cannot be completed due to error.") >>> logger.critical( ... "Notify the %s cannot continue operation due to %s", "program", "some error" ... ) >>> logger.obslog("Observation finished", indent_level=1)