events_protocol.core.logging.logger

Module Contents

class events_protocol.core.logging.logger.Logger(log_name: str, log_format: str = '$BOLD%(asctime)s$RESET %(name)-12s %(levelname)-18s %(message)s', date_format: str = '%Y-%m-%d %H:%M:%S', level: int = logging.INFO, _custom_formatter: logging.Formatter = None)

Bases: logging.LoggerAdapter

This class is responsible to be an interface for other classes and modules use the logging with the Events Protocol format.

Events Protocol.package.utils.Logger

This class is responsible to be an interface for other classes and modules use the logging with the Events Protocol format

HANDLERS :List[StreamHandler]
static _create_log(log_name: str)

Creates the logger object.

log_namestr

The name of the logger.

logging.Logger

return the logging.Logger with the logger name provided.

add_handler(self, handler: logging.Handler, set_formatter: bool = True, formatter: logging.Formatter = None)

Method to add a new handler to the logger with the defined formatter and level.

handlerHandler

The handler class to be added in the logger.

set_formatterbool, optional

If the level and Formatter should be applied, by default True

formatter: logging.Formatter, optional

The custom formatter to be set in the handler.

__add_default_handlers(self)

Method to add the default handlers.

classmethod get_logger(cls, log_name: str, log_format: str = '$BOLD%(asctime)s$RESET %(name)-12s %(levelname)-18s %(message)s', date_format: str = '%Y-%m-%d %H:%M:%S', level: int = logging.INFO, _custom_formatter: logging.Formatter = None)

Get a logger object with Events Protocol Colored Formatter.

log_namestr

Name of the logger instance

log_formatstr, optional

Format of the logger message, by default “$BOLD%(asctime)s$RESET %(name)-12s %(levelname)-18s %(message)s”

date_formatstr, optional

Date format of the logger message, by default “%Y-%m-%d %H:%M:%S”

levelint, optional
The logger level, you can use the ones predefined inside the logging module, or provide an int according to

the following pattern: CRITICAL/FATAL = 50, ERROR = 40, WARNING = 30, INFO = 20, DEBUG = 10, NOTSET = 0. For more information: https://docs.python.org/3/library/logging.html#levels, by default 20 (INFO).

_custom_formatterlogging.Formatter, optional

Replaces the Events Protocol ColoredFormatter by the formatter provided and will ignore the log_format parameter.

logging.Logger

The formatted logger.

class events_protocol.core.logging.logger.ColoredFormatter(msg: str, datefmt: str = '%Y-%m-%d %H:%M:%S', use_color: bool = True)

Bases: logging.Formatter

Events Protocol’s Custom Colored Formatter for Logging.

Events Protocol.package.utils.ColoredFormatter

This class is responsible for setting the format for Events Protocol Loggings, by the default set timestamp and the module name with bold and will use the following color scheme:

GREEN: DEBUG BLUE: INFO YELLOW: WARNING RED: ERROR MAGENTA: CRITICAL

RESET_SEQ = 
COLOR_SEQ = [%dm
BOLD_SEQ = 
COLORS
format(self, record: logging.LogRecord)

Method responsible for formatting the record.

record: logging.LogRecord

The LogRecord with the message to be printed out.

str

The message formatted.

classmethod formatter_message(cls, message: str, use_color: bool = True)

The method to parse the Events Protocol format string.

messagestr

The message to be formatted.

use_colorbool

Flag to signalize if the output should be colored or not.

str

The message formatted.

events_protocol.core.logging.logger.logger_monitor(package_name: str = None, level: int = logging.INFO)

A logger decorator to monitor legacy methods and functions.

package_namestr, optional.

The name of the package where the function or method is located. To get automatically use the __name__ variable.

levelint, optional.

The level of logger to be shown, by default: logging.INFO