class BackgroundThreadTransport(Transport):
    """Aysnchronous transport that uses a background thread.

    Writes logging entries as a batch process.
    """

    def __init__(self, client, name):
        http = copy.deepcopy(client.connection.http)
        http = client.connection.credentials.authorize(http)
        self.client = Client(client.project,
                             client.connection.credentials,
                             http)
        logger = self.client.logger(name)
        self.worker = _Worker(logger)

    def send(self, record, message):
        """Overrides Transport.send().

        :type record: :class:`logging.LogRecord`
        :param record: Python log record that the handler was called with.

        :type message: str
        :param message: The message from the ``LogRecord`` after being
                        formatted by the associated log formatters.
        """
        self.worker.enqueue(record, message)
Example #2
0
class LogHandler:
    def __init__(self):
        if RUBBISH_GEO_ENV == "local":
            logging.basicConfig(level=logging.INFO)
        else:  # [dev, prod]
            self.client = Client()
            self.logger = self.client.logger("functional_api")

    def log_struct(self, struct):
        level = struct.get("level", "info")
        if level == "error":
            struct['traceback'] = traceback.format_exc()

        # SO#57712700
        struct["caller"] = inspect.currentframe().f_back.f_code.co_name

        if RUBBISH_GEO_ENV == "local":
            getattr(logging, level)(json.dumps(struct))
        else:  # [dev, prod]
            self.logger.log_struct(struct)
class BackgroundThreadTransport(Transport):
    """Aysnchronous transport that uses a background thread.

    Writes logging entries as a batch process.
    """
    def __init__(self, client, name):
        http = copy.deepcopy(client._connection.http)
        http = client._connection.credentials.authorize(http)
        self.client = Client(client.project, client._connection.credentials,
                             http)
        logger = self.client.logger(name)
        self.worker = _Worker(logger)

    def send(self, record, message):
        """Overrides Transport.send().

        :type record: :class:`logging.LogRecord`
        :param record: Python log record that the handler was called with.

        :type message: str
        :param message: The message from the ``LogRecord`` after being
                        formatted by the associated log formatters.
        """
        self.worker.enqueue(record, message)