aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-backend/src/__init__.py
blob: a2436a23c3a8d08654356343628a64356fe61f71 (plain) (blame)
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
import asyncio
import logging
import os

from src.settings import CONFIG

# On Windows, the selector event loop is required for aiodns.
if os.name == "nt":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

# Console handler prints to terminal
console_handler = logging.StreamHandler()
level = logging.DEBUG if CONFIG.debug else logging.INFO
console_handler.setLevel(level)

# Remove old loggers, if any
root = logging.getLogger()
if root.handlers:
    for handler in root.handlers:
        root.removeHandler(handler)

# Setup new logging configuration
logging.basicConfig(
    format="%(asctime)s - %(name)s %(levelname)s: %(message)s",
    datefmt="%D %H:%M:%S",
    level=logging.DEBUG if CONFIG.debug else logging.INFO,
    handlers=[console_handler],
)