events_protocol.core.logging

Subpackages

Submodules

Package Contents

class events_protocol.core.logging.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.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_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

class events_protocol.core.logging.PicpayLogger(cls, level: int = logging.INFO, environment: str = 'PRD')

Bases: logging.Logger

Create and format loggers in the PicPay standard format

level: int

Logging level. Set using the enum defined in the logging std library

logging.Logger

Interface to use the logs of the logging library

logger_name = events_protocol
version :str = UNDEFINED
is_production_environment :bool = True
internal_logger :logging.Logger
classmethod set_version(cls, version: str)

Set application version that will be logged

version: str

Application version

__create_logger_with_environment(self, name: str = 'events_protocol', environment: str = 'PRD')

Creates the logger using the desired environment

name: str

Application version

environment: str

Set the current environment that will be used in the application. If it’s PRD or HML it will format the logger in the PicPay application standards. Otherwise it’ll use development settings Default PRD

__dev_log(self, level, message, *args, **kawrgs)

Default logger. Used for development environment.

level: int

Logging level. Set using the enum defined in the logging std library

message: str

Message that will be send to the logger

__prod_log(self, level, message, *args, **kwargs)

Production format logger. Used for production and QA environment.

level: int

Logging level. Set using the enum defined in the logging std library

message: str

Message that will be send to the logger

_log(self, level, message, *args, **kwargs)

Overrides log method of the logging library

level: int

Logging level. Set using the enum defined in the logging std library

message: str

Message that will be send to the logger