1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
4 """Logging utilities for Arvados clients"""
8 log_format = '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s'
9 log_date_format = '%Y-%m-%d %H:%M:%S'
10 log_handler = logging.StreamHandler()
11 log_handler.setFormatter(logging.Formatter(log_format, log_date_format))
13 class GoogleHTTPClientFilter:
14 """Common googleapiclient.http log filters for Arvados clients
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:
21 logging.getLogger('googleapiclient.http').addFilter(GoogleHTTPClientFilter())
23 def __init__(self, *, retry_level='INFO'):
24 self.retry_levelname = retry_level
25 self.retry_levelno = getattr(logging, retry_level)
27 def filter(self, record):
28 if record.msg.startswith(('Sleeping ', 'Retry ')):
29 record.levelname = self.retry_levelname
30 record.levelno = self.retry_levelno