From 534d99bb87e6abb96cdab3a34dab9cf432e2ee09 Mon Sep 17 00:00:00 2001 From: bmc-msft <41130664+bmc-msft@users.noreply.github.com> Date: Thu, 1 Oct 2020 14:57:09 -0400 Subject: [PATCH] Set log levels in Azure Functions by hand for 3rd party libraries (#63) --- .../__app__/onefuzzlib/azure/creds.py | 3 +- .../__app__/onefuzzlib/azure/monkeypatch.py | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/api-service/__app__/onefuzzlib/azure/creds.py b/src/api-service/__app__/onefuzzlib/azure/creds.py index e630d6c85..4c87db0b0 100644 --- a/src/api-service/__app__/onefuzzlib/azure/creds.py +++ b/src/api-service/__app__/onefuzzlib/azure/creds.py @@ -19,7 +19,7 @@ from memoization import cached from msrestazure.azure_active_directory import MSIAuthentication from msrestazure.tools import parse_resource_id -from .monkeypatch import allow_more_workers +from .monkeypatch import allow_more_workers, reduce_logging @cached(ttl=60) @@ -30,6 +30,7 @@ def get_msi() -> MSIAuthentication: @cached(ttl=60) def mgmt_client_factory(client_class: Any) -> Any: allow_more_workers() + reduce_logging() try: return get_client_from_cli_profile(client_class) except CLIError: diff --git a/src/api-service/__app__/onefuzzlib/azure/monkeypatch.py b/src/api-service/__app__/onefuzzlib/azure/monkeypatch.py index de06c786b..bac10666e 100644 --- a/src/api-service/__app__/onefuzzlib/azure/monkeypatch.py +++ b/src/api-service/__app__/onefuzzlib/azure/monkeypatch.py @@ -7,6 +7,7 @@ import inspect import logging WORKERS_DONE = False +REDUCE_LOGGING = False def allow_more_workers() -> None: @@ -22,3 +23,34 @@ def allow_more_workers() -> None: entry.frame.f_locals["self"]._sync_call_tp._max_workers = 50 WORKERS_DONE = True + + +# TODO: Replace this with a better method for filtering out logging +# See https://github.com/Azure/azure-functions-python-worker/issues/743 +def reduce_logging() -> None: + global REDUCE_LOGGING + if REDUCE_LOGGING: + return + + to_quiet = [ + "azure", + "cli", + "grpc", + "concurrent", + "oauthlib", + "msrest", + "opencensus", + "urllib3", + "requests", + "aiohttp", + "asyncio", + "adal-python", + ] + + for name in logging.Logger.manager.loggerDict: # type: ignore + logger = logging.getLogger(name) + for prefix in to_quiet: + if logger.name.startswith(prefix): + logger.level = logging.WARN + + REDUCE_LOGGING = True