pipert.utils.visualizer.logger

Module Contents

Classes

_ColorfulFormatter

Formatter instances are used to convert a LogRecord to text.

Functions

setup_logger(output=None, distributed_rank=0, *, color=True, name='detectron2', abbrev_name=None)

Initialize the detectron2 logger and set its verbosity level to “DEBUG”.

_cached_log_stream(filename)

_find_caller()

Returns:

log_first_n(lvl, msg, n=1, *, name=None, key='caller')

Log only for the first n times.

log_every_n(lvl, msg, n=1, *, name=None)

Log once per n times.

log_every_n_seconds(lvl, msg, n=1, *, name=None)

Log no more than once per n seconds.

create_small_table(small_dict)

Create a small table using the keys of small_dict as headers. This is only

class pipert.utils.visualizer.logger._ColorfulFormatter(*args, **kwargs)[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 default value of “%s(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

formatMessage(self, record)[source]
pipert.utils.visualizer.logger.setup_logger(output=None, distributed_rank=0, *, color=True, name='detectron2', abbrev_name=None)[source]

Initialize the detectron2 logger and set its verbosity level to “DEBUG”. Args:

output (str): a file name or a directory to save log. If None, will not save log file.

If ends with “.txt” or “.log”, assumed to be a file name. Otherwise, logs will be saved to output/log.txt.

name (str): the root module name of this logger abbrev_name (str): an abbreviation of the module, to avoid long names in logs.

Set to “” to not log the root module in logs. By default, will abbreviate “detectron2” to “d2” and leave other modules unchanged.

Returns:

logging.Logger: a logger

pipert.utils.visualizer.logger._cached_log_stream(filename)[source]
pipert.utils.visualizer.logger._find_caller()[source]

Returns: str: module name of the caller tuple: a hashable key to be used to identify different callers

pipert.utils.visualizer.logger._LOG_COUNTER[source]
pipert.utils.visualizer.logger._LOG_TIMER[source]
pipert.utils.visualizer.logger.log_first_n(lvl, msg, n=1, *, name=None, key='caller')[source]

Log only for the first n times. Args:

lvl (int): the logging level msg (str): n (int): name (str): name of the logger to use. Will use the caller’s module by default. key (str or tuple[str]): the string(s) can be one of “caller” or

“message”, which defines how to identify duplicated logs. For example, if called with n=1, key=”caller”, this function will only log the first call from the same caller, regardless of the message content. If called with n=1, key=”message”, this function will log the same content only once, even if they are called from different places. If called with n=1, key=(“caller”, “message”), this function will not log only if the same caller has logged the same message before.

pipert.utils.visualizer.logger.log_every_n(lvl, msg, n=1, *, name=None)[source]

Log once per n times. Args:

lvl (int): the logging level msg (str): n (int): name (str): name of the logger to use. Will use the caller’s module by default.

pipert.utils.visualizer.logger.log_every_n_seconds(lvl, msg, n=1, *, name=None)[source]

Log no more than once per n seconds. Args:

lvl (int): the logging level msg (str): n (int): name (str): name of the logger to use. Will use the caller’s module by default.

pipert.utils.visualizer.logger.create_small_table(small_dict)[source]

Create a small table using the keys of small_dict as headers. This is only suitable for small dictionaries. Args:

small_dict (dict): a result dictionary of only a few items.

Returns:

str: the table as a string.