35 lines
768 B
Python
35 lines
768 B
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# @Time : 2022/05/14 2:20 PM
|
|
# @Author : yommi
|
|
# @Site :
|
|
# @File : debugger.py
|
|
# @Software: PyCharm
|
|
|
|
import logging
|
|
|
|
|
|
logging.basicConfig(
|
|
level=logging.DEBUG,
|
|
format="[%(asctime)s] [%(levelname)s] %(name)s: %(message)s",
|
|
datefmt="%Y-%m-%d %H:%M:%S %z",
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Debugger:
|
|
"""Debug a method and return it back"""
|
|
|
|
def __init__(self, func):
|
|
self.func = func
|
|
|
|
def __call__(self, *args, **kwargs):
|
|
logger.debug(f"Entering : {self.func.__name__}")
|
|
logger.debug(f"args, kwargs : {args, kwargs}")
|
|
|
|
result = self.func(*args, **kwargs)
|
|
|
|
logger.debug(f"{self.func.__name__} returned : {result}")
|
|
|
|
return result
|