31 lines
719 B
Python
31 lines
719 B
Python
|
import asyncio
|
||
|
import logging
|
||
|
|
||
|
from .config import Config
|
||
|
|
||
|
|
||
|
def run_async(future: asyncio.Future) -> None:
|
||
|
global logger
|
||
|
loop = asyncio.new_event_loop()
|
||
|
try:
|
||
|
loop.run_until_complete(future)
|
||
|
except asyncio.exceptions.CancelledError:
|
||
|
loop.run_until_complete(asyncio.sleep(0.25))
|
||
|
finally:
|
||
|
loop.stop()
|
||
|
|
||
|
|
||
|
def setup_logger(name: str = __name__) -> logging.Logger:
|
||
|
logger = logging.getLogger(name)
|
||
|
|
||
|
logger.setLevel(Config.LOGLEVEL)
|
||
|
ch = logging.StreamHandler()
|
||
|
ch.setLevel(Config.LOGLEVEL)
|
||
|
formatter = logging.Formatter(
|
||
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||
|
ch.setFormatter(formatter)
|
||
|
|
||
|
logger.addHandler(ch)
|
||
|
|
||
|
return logger
|