fixms.logger#

Logging module for FixMS

Attributes#

Classes#

CustomFormatter

Formatter instances are used to convert a LogRecord to text.

LoggerWithHistory

Custom logger that will also update the HISTORY table in the MS.

TqdmToLogger

Output stream for TQDM which will output to logger module instead of

Functions#

get_fixms_logger(→ LoggerWithHistory)

Will construct a logger object.

update_history(→ None)

Module Contents#

class fixms.logger.CustomFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]#

Bases: logging.Formatter

Formatter instances are used to convert a LogRecord to text.

Formatters need to know how a LogRecord is constructed. They are responsible for converting a LogRecord to (usually) a string which can be interpreted by either a human or an external system. The base Formatter allows a formatting string to be specified. If none is supplied, the style-dependent default value, “%(message)s”, “{message}”, or “${message}”, is used.

The Formatter can be initialized with a format string which makes use of knowledge of the LogRecord attributes - e.g. the default value mentioned above makes use of the fact that the user’s message and arguments are pre- formatted into a LogRecord’s message attribute. Currently, the useful attributes in a LogRecord are described by:

%(name)s Name of the logger (logging channel) %(levelno)s Numeric logging level for the message (DEBUG, INFO,

WARNING, ERROR, CRITICAL)

%(levelname)s Text logging level for the message (“DEBUG”, “INFO”,

“WARNING”, “ERROR”, “CRITICAL”)

%(pathname)s Full pathname of the source file where the logging

call was issued (if available)

%(filename)s Filename portion of pathname %(module)s Module (name portion of filename) %(lineno)d Source line number where the logging call was issued

(if available)

%(funcName)s Function name %(created)f Time when the LogRecord was created (time.time()

return value)

%(asctime)s Textual time when the LogRecord was created %(msecs)d Millisecond portion of the creation time %(relativeCreated)d Time in milliseconds when the LogRecord was created,

relative to the time the logging module was loaded (typically at application startup time)

%(thread)d Thread ID (if available) %(threadName)s Thread name (if available) %(process)d Process ID (if available) %(message)s The result of record.getMessage(), computed just as

the record is emitted

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.

FORMATS[source]#
blue = '\x1b[34;20m'[source]#
bold_red = '\x1b[31;1m'[source]#
format_str = '%(asctime)s.%(msecs)03d %(module)s - %(funcName)s: %(message)s'[source]#
green = '\x1b[32;20m'[source]#
grey = '\x1b[38;20m'[source]#
red = '\x1b[31;20m'[source]#
reset = '\x1b[0m'[source]#
yellow = '\x1b[33;20m'[source]#
class fixms.logger.LoggerWithHistory(*args, **kwargs)[source]#

Bases: logging.Logger

Custom logger that will also update the HISTORY table in the MS.

critical(message, *args, ms=None, app_params=[], **kwargs)[source]#

Log ‘msg % args’ with severity ‘CRITICAL’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.critical(“Houston, we have a %s”, “major disaster”, exc_info=1)

debug(message, *args, ms=None, app_params=[], **kwargs)[source]#

Log ‘msg % args’ with severity ‘DEBUG’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.debug(“Houston, we have a %s”, “thorny problem”, exc_info=1)

error(message, *args, ms=None, app_params=[], **kwargs)[source]#

Log ‘msg % args’ with severity ‘ERROR’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.error(“Houston, we have a %s”, “major problem”, exc_info=1)

info(message, *args, ms=None, app_params=[], **kwargs)[source]#

Log ‘msg % args’ with severity ‘INFO’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.info(“Houston, we have a %s”, “interesting problem”, exc_info=1)

log(level, message, *args, ms=None, app_params=[], **kwargs)[source]#

Log ‘msg % args’ with the integer severity ‘level’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.log(level, “We have a %s”, “mysterious problem”, exc_info=1)

warning(message, *args, ms=None, app_params=[], **kwargs)[source]#

Log ‘msg % args’ with severity ‘WARNING’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.warning(“Houston, we have a %s”, “bit of a problem”, exc_info=1)

class fixms.logger.TqdmToLogger(logger, level=None)[source]#

Bases: io.StringIO

Output stream for TQDM which will output to logger module instead of the StdOut.

flush()[source]#

Flush write buffers, if applicable.

This is not implemented for read-only and non-blocking streams.

write(buf)[source]#

Write string to file.

Returns the number of characters written, which is always equal to the length of the string.

buf = ''[source]#
level = None[source]#
logger = None[source]#
fixms.logger.get_fixms_logger(name: str = 'fixms', attach_handler: bool = True) LoggerWithHistory[source]#

Will construct a logger object.

Parameters:
  • name (str, optional) – Name of the logger to attempt to use. This is ignored if in a prefect flowrun. Defaults to ‘arrakis’.

  • attach_handler (bool, optional) – Attacjes a custom StreamHandler. Defaults to True.

Returns:

The appropriate logger

Return type:

logging.Logger

fixms.logger.update_history(ms: str, message: str, app_params: List[str] = [], obs_id: int = 0, priority: str = 'NORMAL') None[source]#
fixms.logger.logger[source]#