File size: 1,879 Bytes
b152010
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import logging
import sys
import warnings
import os


def configure_logging_libs(debug=False):
    warnings.filterwarnings(
      action="ignore", category=UserWarning, module="pyannote"
    )
    modules = [
      "numba", "httpx", "markdown_it", "speechbrain", "fairseq", "pyannote",
      "faiss",
      "pytorch_lightning.utilities.migration.utils",
      "pytorch_lightning.utilities.migration",
      "pytorch_lightning",
      "lightning",
      "lightning.pytorch.utilities.migration.utils",
    ]
    try:
        for module in modules:
            logging.getLogger(module).setLevel(logging.WARNING)
        os.environ['TF_CPP_MIN_LOG_LEVEL'] = "3" if not debug else "1"

        # fix verbose pyannote audio
        def fix_verbose_pyannote(*args, what=""):
            pass
        import pyannote.audio.core.model # noqa
        pyannote.audio.core.model.check_version = fix_verbose_pyannote
    except Exception as error:
        logger.error(str(error))


def setup_logger(name_log):
    logger = logging.getLogger(name_log)
    logger.setLevel(logging.INFO)

    _default_handler = logging.StreamHandler()  # Set sys.stderr as stream.
    _default_handler.flush = sys.stderr.flush
    logger.addHandler(_default_handler)

    logger.propagate = False

    handlers = logger.handlers

    for handler in handlers:
        formatter = logging.Formatter("[%(levelname)s] >> %(message)s")
        handler.setFormatter(formatter)

    # logger.handlers

    return logger


logger = setup_logger("sonitranslate")
logger.setLevel(logging.INFO)


def set_logging_level(verbosity_level):
    logging_level_mapping = {
        "debug": logging.DEBUG,
        "info": logging.INFO,
        "warning": logging.WARNING,
        "error": logging.ERROR,
        "critical": logging.CRITICAL,
    }

    logger.setLevel(logging_level_mapping.get(verbosity_level, logging.INFO))