persia.logger

Module Contents

class persia.logger.levelFilter(level)

Bases: logging.Filter

Log level filter.

Parameters:

level (int) – filter log level. Only logs with level higher than level will be kept.

Initialize a filter.

Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.

filter(record)

Filter the log record whose level is greater than the preset log level.

Parameters:

record (logging.LogRecord) – callback function input record items.

Return type:

bool

persia.logger.get_default_logger(name=None, **kwargs)

Get the default logger. If default logger is not set, init the default by the given name.

Parameters:

name (str, optional) – logger name.

Return type:

logging.Logger

persia.logger.get_logger(name)

Get logger by name.

Parameters:

name (str) – logger name.

Return type:

logging.Logger

persia.logger.setLogger(name, log_level=logging.DEBUG, log_filename='train.log', enable_file_logger=False, err_redirect_filepath='error.log', enable_err_redirect=False, err_redirect_level=logging.INFO)

Helper function to simplify the logger setup process with provided log_level and log_filename. Also makes it possible to redirect logs above a certain level to a different file.

Parameters:
  • name (str) – logger name

  • log_filename (str) – log filename

  • enable_file_logger (bool) – whether enable save log into file

  • err_redirect_filepath (str) – err log redirect filepath

  • enable_err_redirect (bool) – whether enable err log redirect

  • err_redirect_level (int) – error redirect log level

  • log_level (int) –

Return type:

logging.Logger

persia.logger.COLOR_FORMATTER
persia.logger.DEFAULT_LOGGER_NAME = log
persia.logger.FILE_LOG_FORMAT = %(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s
persia.logger.FORMATTER
persia.logger.LOG_COLOR
persia.logger.STREAM_LOG_FORMAT = %(log_color)s%(asctime)s %(levelname)-8s%(reset)s %(blue)s[%(filename)s:%(lineno)d]%(reset)s...