Ejemplo n.º 1
0
    def exception(self, pos, debug=False, format=None, *args, **kwargs):
        """
        Logs a message within an exception.

        Args:
            pos (str): Either a string to use to send a message to the
                       StreamHandler or a key that's used to access a
                       dictionary, passed through format
            debug (bool): Flag to log exception on DEBUG level instead of EXCEPTION one
            format (dict): An optional dictionary which can contain strings as
                           "key"/"item" pairs, which would be used to replace
                           formatted text that's passed from self.__getitem__
            args (any): Any additional variables to pass to the logger instance
            kwargs (any): Any additional keywords to pass to the logger instance
        """
        kwargs['exc_info'] = True
        message = self.__getitem__(pos)
        message = str(message)
        fmt = UnseenFormatter()
        message = fmt.format(message, **format)

        if debug:
            if isinstance(pos, six.string_types):
                message = pos

            self.debug(message, *args, **kwargs)
        else:
            if isinstance(pos, six.string_types):
                message = pos

            self.log(logging.EXCEPTION, message, *args, **kwargs)
Ejemplo n.º 2
0
    def critical(self, pos, format=None, *args, **kwargs):
        """
        Logs a message with level CRITICAL.

        Args:
            pos (str): Either a string to use to send a message to the
                       StreamHandler or a key that's used to access a
                       dictionary, passed through format
            format (dict): An optional dictionary which can contain strings as
                           "key"/"item" pairs, which would be used to replace
                           formatted text that's passed from self.__getitem__
            args (any): Any additional variables to pass to the logger instance
            kwargs (any): Any additional keywords to pass to the logger instance
        """
        if format is None:
            message = self.__getitem__(pos)
        else:
            message = self.__getitem__(pos)
            message = str(message)
            fmt = UnseenFormatter()
            message = fmt.format(message, **format)

        if isinstance(pos, six.string_types):
            # override previous if pos is a regular logging string
            message = pos

        self.__logger.critical(message, *args, **kwargs)
Ejemplo n.º 3
0
    def log(self, level, pos, message, *args, **kwargs):
        """
        Logs a message with given level.

        Args:
            level (int): log level to use
            pos (str): Either a string to use to send a message to the
                       StreamHandler or a key that's used to access a
                       dictionary, passed through format
            message (str): Message to log
            args (any): Any additional variables to pass to the logger instance
            kwargs (any): Any additional keywords to pass to the logger instance
        """
        message = self.__getitem__(pos)
        message = str(message)
        fmt = UnseenFormatter()
        message = fmt.format(message, **format)

        if isinstance(pos, six.string_types):
            # override previous if pos is a regular logging string
            message = pos

        self.__logger.log(level, message, *args, **kwargs)