aboutsummaryrefslogtreecommitdiff
path: root/labbot/logger.py
blob: 0acf78f453bd5ec93e00d2a77b989566176ec480 (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
import sys
import logging

def init(level: int) -> None:
    logger = logging.getLogger()
    logger.setLevel(level)

    aiohttp_logger = logging.getLogger("aiohttp")
    aiohttp_logger.setLevel(logging.WARNING)

    asyncio_logger = logging.getLogger("asyncio")
    asyncio_logger.setLevel(logging.WARNING)

    formatter = logging.Formatter(
        "[{asctime}] [{levelname}] {name}: {message}", datefmt="%Y-%m-%d %H:%M:%S", style="{"
    )

    if not sys.stdout.closed:
        stdout_handler = logging.StreamHandler(sys.stdout)
        stdout_handler.setFormatter(formatter)

        logger.addHandler(stdout_handler)


    logging.captureWarnings(True)