summaryrefslogtreecommitdiff
path: root/buildscripts/util/cmdutils.py
blob: d5d8b167a8b4d77f816d68eeafd8fd729b09dbbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Utilities for build commandline applications."""
import logging
import sys

import structlog

EXTERNAL_LOGGERS = {
    "evergreen",
    "git",
    "inject",
    "urllib3",
}


def enable_logging(verbose: bool) -> None:
    """
    Enable logging for execution.

    :param verbose: Should verbose logging be enabled.
    """
    level = logging.DEBUG if verbose else logging.INFO
    logging.basicConfig(
        format="[%(asctime)s - %(name)s - %(levelname)s] %(message)s",
        level=level,
        stream=sys.stdout,
    )
    structlog.configure(logger_factory=structlog.stdlib.LoggerFactory())
    for log_name in EXTERNAL_LOGGERS:
        logging.getLogger(log_name).setLevel(logging.WARNING)