|
17 | 17 | from collections import deque |
18 | 18 | import copy |
19 | 19 | import hashlib |
| 20 | +import inspect |
20 | 21 | import json |
| 22 | +import logging |
21 | 23 | import os |
22 | 24 | import sys |
23 | 25 | import threading |
|
33 | 35 | import oauth2client |
34 | 36 | from oauth2client.contrib.gce import AppAssertionCredentials |
35 | 37 |
|
36 | | -import googleclouddebugger |
37 | 38 | import cdbg_native as native |
38 | 39 | import uniquifier_computer |
| 40 | +import googleclouddebugger |
39 | 41 |
|
40 | 42 | # This module catches all exception. This is safe because it runs in |
41 | 43 | # a daemon thread (so we are not blocking Ctrl+C). We need to catch all |
|
54 | 56 | # a map is optional environment variable that can be used to set the flag |
55 | 57 | # (flags still take precedence). |
56 | 58 | _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'} |
60 | 62 |
|
61 | 63 | # Debuggee labels used to format debuggee description (ordered). The minor |
62 | 64 | # version is excluded for the sake of consistency with AppEngine UX. |
@@ -92,6 +94,28 @@ def __init__(self): |
92 | 94 | self._transmission_queue = deque(maxlen=100) |
93 | 95 | self._new_updates = threading.Event(False) |
94 | 96 |
|
| 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 | + |
95 | 119 | # |
96 | 120 | # Configuration options (constants only modified by unit test) |
97 | 121 | # |
|
0 commit comments