Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Set log levels in Azure Functions by hand for 3rd party libraries #63

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/api-service/__app__/onefuzzlib/azure/creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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)
Expand All @@ -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:
Expand Down
32 changes: 32 additions & 0 deletions src/api-service/__app__/onefuzzlib/azure/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging

WORKERS_DONE = False
REDUCE_LOGGING = False


def allow_more_workers() -> None:
Expand All @@ -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