Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
pp-python-commons / loggers.py
Size: Mime:
import functools
import logging
from typing import Dict

LOGGER = logging.getLogger(__name__)


class LoggingBase:
    loggers: Dict[str, str] = None

    def __init__(self):
        self.logger = LOGGER

        for logging_call_name, log_level in self.loggers.items():
            level_name = logging.getLevelName(log_level).lower()
            logger_level = getattr(self.logger, level_name)

            wrapped_log = self.wrapper_log(logger_level, logging_call_name)

            setattr(self, logging_call_name, wrapped_log)
            getattr(self, logging_call_name).__name__ = logging_call_name

    def wrapper_log(self, func, msg_prefix):
        @functools.wraps(func)
        def wrapper(msg, *args, **kwargs):
            concat_msg_name = msg_prefix + ", " + msg
            return func(concat_msg_name, *args, **kwargs)

        return wrapper