pint.logging.LogFilter

class pint.logging.LogFilter(onlyonce=None, never=None, onlyonce_level='INFO')[source]

Bases: object

Custom logging filter for loguru. Define some messages that are never seen (e.g., Deprecation Warnings). Others that will only be seen once. Filtering of those is done on the basis of regular expressions.

Define regexs for messages that will only be seen once. Use \S+ for a variable that might change. If a message comes through with a new value for that variable, it will be seen.

Make sure to escape other regex commands like ().

Each message starts with state = False. Once it has been emitted, that changes to a list of the messages so that it can keep track. These are only suppressed when issued at level onlyonce_level or lower (e.g., if onlyonce_level is INFO, then WARNING will always come through)

They should be defined as:

r”Error message”: False

where the False tracks whether or not the message has been issued at all.

Parameters:
  • onlyonce (list, optional) – list of messages that should only be issued once if at INFO or below. Checked using re.match, so must match from beginning of message.

  • never (list, optional) – list of messages that should never be seen. Checked using re.search, so can match anywhere in message.

  • onlyonce_level (str, optional) – level below which messages will only be shown once

Methods

filter(record)

Filter the record based on record["message"] and record["level"] If this returns s,``False``, the message is not seen

filter(record)[source]

Filter the record based on record["message"] and record["level"] If this returns s,``False``, the message is not seen

Parameters:

record (dict) – should contain record["message"] and record["level"]

Returns:

If True, message is seen. If False, message is not seen

Return type:

bool

__call__(record)[source]

Call self as a function.