pypeit.logger module
PypeIt logging
Implementation heavily references loggers from astropy and sdsstools.
- class pypeit.logger.DebugStreamFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]
Bases:
StreamFormatterSet the base logging level to DEBUG
- base_level = 10
The base logging level for the class. Used to determine whether or not to include the calling frame in the log message.
- class pypeit.logger.FileFormatter(fmt='%(levelname)8s | %(asctime)s | %(filename)s:%(funcName)s:%(lineno)s | %(message)s')[source]
Bases:
FormatterCustom Formatter <logging.Formatter> for the file handler.
- base_fmt = '%(levelname)8s | %(asctime)s | %(filename)s:%(funcName)s:%(lineno)s | %(message)s'
- class pypeit.logger.PypeItLogger(name, level=0)[source]
Bases:
LoggerCustom logging system for pypeit.
This borrows heavily from implementations in astropy and sdsstools.
- _excepthook(etype, value, trace)[source]
Override the default exception hook to log an error message.
- _excepthook_orig = None
- static convert_verbosity_to_logging_level(v)[source]
Given a PypeIt “verbosity level,” return the logging level.
- Parameters:
v (int) – PypeIt verbosity level (0, 1, or 2)
- Returns:
Corresponding logging level
- Return type:
- Raises:
ValueError – Raised if the input verbosity level is not 0, 1, or 2.
- init(level=20, stream=None, log_file=None, log_file_level=None)[source]
Initialise the logger.
- Parameters:
level (
int) – The logging level printed to the consolestream (
TextIOBase|None) – Stream for logging messages, which defaults to sys.stderr.log_file (
str|Path|None) – Name for a log file. If None, logging is only recorded to the console. If the file provided already exists, it will be overwritten!log_file_level (
int|None) – The logging level specific to the log file. If None, adopt the console logging level.
- class pypeit.logger.StreamFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]
Bases:
FormatterCustom Formatter <logging.Formatter> for the stream handler.
- base_level = None
The base logging level for the class. Used to determine whether or not to include the calling frame in the log message.
- format(record)[source]
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- pypeit.logger.clear_text_color(text)[source]
Remove escape characters that colorize the text in a string.
- pypeit.logger.color_text(text, color, bold=False, nchar=None)[source]
Return an input string with escape characters to colorize text written to consoles.
- pypeit.logger.get_logger(level=20, stream=None, log_file=None, log_file_level=None)[source]
Instantiate a new logger.
- Parameters:
level (
int) – The logging level printed to the consolestream (
TextIOBase|None) – Stream for logging messages, which defaults to sys.stderr.log_file (
str|Path|None) – Name for a log file. If None, logging is only recorded to the console. If the file provided already exists, it will be ovewritten!log_file_level (
int|None) – The logging level specific to the log file. If None, adopt the console logging level.
- Return type:
- Returns:
Logging object for PypeIt.
- pypeit.logger.short_warning(message, category, filename, lineno, line=None)[source]
Overrides default formatting of warning messages. The only arguments used are
messageandcategory. Seewarnings.formatwarning().