Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 7658089

Browse files
committed
Filter out logging from apiclients.discovery
The discovery module logs every URL it creates, which gets very noisy in managed VMs. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=118244832
1 parent 4d8c5b8 commit 7658089

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/googleclouddebugger/gcp_hub_client.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from collections import deque
1818
import copy
1919
import hashlib
20+
import inspect
2021
import json
22+
import logging
2123
import os
2224
import sys
2325
import threading
@@ -33,9 +35,9 @@
3335
import oauth2client
3436
from oauth2client.contrib.gce import AppAssertionCredentials
3537

36-
import googleclouddebugger
3738
import cdbg_native as native
3839
import uniquifier_computer
40+
import googleclouddebugger
3941

4042
# This module catches all exception. This is safe because it runs in
4143
# a daemon thread (so we are not blocking Ctrl+C). We need to catch all
@@ -54,9 +56,9 @@
5456
# a map is optional environment variable that can be used to set the flag
5557
# (flags still take precedence).
5658
_DEBUGGEE_LABELS = {
57-
'module' : 'GAE_MODULE_NAME',
58-
'version' : 'GAE_MODULE_VERSION',
59-
'minorversion' : 'GAE_MINOR_VERSION'}
59+
'module': 'GAE_MODULE_NAME',
60+
'version': 'GAE_MODULE_VERSION',
61+
'minorversion': 'GAE_MINOR_VERSION'}
6062

6163
# Debuggee labels used to format debuggee description (ordered). The minor
6264
# version is excluded for the sake of consistency with AppEngine UX.
@@ -92,6 +94,28 @@ def __init__(self):
9294
self._transmission_queue = deque(maxlen=100)
9395
self._new_updates = threading.Event(False)
9496

97+
# Disable logging in the discovery API to avoid excessive logging.
98+
class _ChildLogFilter(logging.Filter):
99+
"""Filter to eliminate info-level logging when called from this module."""
100+
101+
def __init__(self, filter_levels=None):
102+
super(_ChildLogFilter, self).__init__()
103+
self._filter_levels = filter_levels or set(logging.INFO)
104+
# Get name without extension to avoid .py vs .pyc issues
105+
self._my_filename = os.path.splitext(
106+
inspect.getmodule(_ChildLogFilter).__file__)[0]
107+
108+
def filter(self, record):
109+
if record.levelno not in self._filter_levels:
110+
return True
111+
callerframes = inspect.getouterframes(inspect.currentframe())
112+
for f in callerframes:
113+
if os.path.splitext(f[1])[0] == self._my_filename:
114+
return False
115+
return True
116+
self._log_filter = _ChildLogFilter({logging.INFO})
117+
discovery.logger.addFilter(self._log_filter)
118+
95119
#
96120
# Configuration options (constants only modified by unit test)
97121
#

0 commit comments

Comments
 (0)