arvados.logging

Logging utilities for Arvados clients

 1# Copyright (C) The Arvados Authors. All rights reserved.
 2#
 3# SPDX-License-Identifier: Apache-2.0
 4"""Logging utilities for Arvados clients"""
 5
 6import logging
 7
 8log_format = '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s'
 9log_date_format = '%Y-%m-%d %H:%M:%S'
10log_handler = logging.StreamHandler()
11log_handler.setFormatter(logging.Formatter(log_format, log_date_format))
12
13class GoogleHTTPClientFilter:
14    """Common googleapiclient.http log filters for Arvados clients
15
16    This filter makes `googleapiclient.http` log messages more useful for
17    typical Arvados applications. Currently it only changes the level of
18    retry messages (to INFO by default), but its functionality may be
19    extended in the future. Typical usage looks like:
20
21        logging.getLogger('googleapiclient.http').addFilter(GoogleHTTPClientFilter())
22    """
23    def __init__(self, *, retry_level='INFO'):
24        self.retry_levelname = retry_level
25        self.retry_levelno = getattr(logging, retry_level)
26
27    def filter(self, record):
28        if record.msg.startswith(('Sleeping ', 'Retry ')):
29            record.levelname = self.retry_levelname
30            record.levelno = self.retry_levelno
31        return True
log_format = '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s'
log_date_format = '%Y-%m-%d %H:%M:%S'
log_handler = <StreamHandler (NOTSET)>
class GoogleHTTPClientFilter:
14class GoogleHTTPClientFilter:
15    """Common googleapiclient.http log filters for Arvados clients
16
17    This filter makes `googleapiclient.http` log messages more useful for
18    typical Arvados applications. Currently it only changes the level of
19    retry messages (to INFO by default), but its functionality may be
20    extended in the future. Typical usage looks like:
21
22        logging.getLogger('googleapiclient.http').addFilter(GoogleHTTPClientFilter())
23    """
24    def __init__(self, *, retry_level='INFO'):
25        self.retry_levelname = retry_level
26        self.retry_levelno = getattr(logging, retry_level)
27
28    def filter(self, record):
29        if record.msg.startswith(('Sleeping ', 'Retry ')):
30            record.levelname = self.retry_levelname
31            record.levelno = self.retry_levelno
32        return True

Common googleapiclient.http log filters for Arvados clients

This filter makes googleapiclient.http log messages more useful for typical Arvados applications. Currently it only changes the level of retry messages (to INFO by default), but its functionality may be extended in the future. Typical usage looks like:

logging.getLogger('googleapiclient.http').addFilter(GoogleHTTPClientFilter())
GoogleHTTPClientFilter(*, retry_level='INFO')
24    def __init__(self, *, retry_level='INFO'):
25        self.retry_levelname = retry_level
26        self.retry_levelno = getattr(logging, retry_level)
retry_levelname
retry_levelno
def filter(self, record):
28    def filter(self, record):
29        if record.msg.startswith(('Sleeping ', 'Retry ')):
30            record.levelname = self.retry_levelname
31            record.levelno = self.retry_levelno
32        return True