blob: 48736d5617ff0059ed2cacf826334f6a26bd29e3 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import contextlib
6import logging
7import os
8
9from pylib.constants import host_paths
10
11_REQUESTS_PATH = os.path.join(
12 host_paths.DIR_SOURCE_ROOT, 'third_party', 'requests', 'src')
13_APPURIFY_PYTHON_PATH = os.path.join(
14 host_paths.DIR_SOURCE_ROOT, 'third_party', 'appurify-python', 'src')
15
16with host_paths.SysPath(_REQUESTS_PATH), (
17 host_paths.SysPath(_APPURIFY_PYTHON_PATH)):
18
19 handlers_before = list(logging.getLogger().handlers)
20
21 import appurify.api # pylint: disable=import-error
22 import appurify.utils # pylint: disable=import-error
23
24 handlers_after = list(logging.getLogger().handlers)
25 new_handler = list(set(handlers_after) - set(handlers_before))
26 while new_handler:
27 logging.info("Removing logging handler.")
28 logging.getLogger().removeHandler(new_handler.pop())
29
30 api = appurify.api
31 utils = appurify.utils
32
33# This is not thread safe. If multiple threads are ever supported with appurify
34# this may cause logging messages to go missing.
35@contextlib.contextmanager
36def SanitizeLogging(verbose_count, level):
37 if verbose_count < 2:
38 logging.disable(level)
39 yield True
40 logging.disable(logging.NOTSET)
41 else:
42 yield False
43