26 lines
737 B
Python
26 lines
737 B
Python
from dotenv import load_dotenv
|
|
import logging
|
|
import os
|
|
from configparser import ConfigParser
|
|
from pathlib import Path
|
|
from typing import Literal
|
|
|
|
|
|
# load default values
|
|
config = ConfigParser()
|
|
config.read(Path(__file__).parent / 'defaults.ini')
|
|
LOGGER_LEVEL = config.get('main', 'logger_level')
|
|
|
|
|
|
def setup_logging(
|
|
logger_level: Literal['debug', 'info', 'warning', 'error'] = LOGGER_LEVEL
|
|
):
|
|
fmt = '%(asctime)s | %(levelname)s | %(filename)s | %(funcName)s | %(message)s'
|
|
datefmt = '%Y-%m-%d %H:%M:%S'
|
|
level = getattr(logging, logger_level.upper())
|
|
logging.basicConfig(format=fmt, datefmt=datefmt, level=level)
|
|
logging.debug('finished')
|
|
|
|
if __name__ == '__main__':
|
|
load_dotenv('dev.env')
|
|
setup_logging() |