mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-09 22:10:56 +08:00
Fix some warnings in log.py. (#805)
* Fix some warnings in log.py. * Fix typo and using black format. * Fix black. * Rename dict_ to attrs
This commit is contained in:
13
qlib/log.py
13
qlib/log.py
@@ -13,12 +13,12 @@ from .config import C
|
||||
|
||||
|
||||
class MetaLogger(type):
|
||||
def __new__(cls, name, bases, dict):
|
||||
def __new__(mcs, name, bases, attrs):
|
||||
wrapper_dict = logging.Logger.__dict__.copy()
|
||||
for key in wrapper_dict:
|
||||
if key not in dict and key != "__reduce__":
|
||||
dict[key] = wrapper_dict[key]
|
||||
return type.__new__(cls, name, bases, dict)
|
||||
if key not in attrs and key != "__reduce__":
|
||||
attrs[key] = wrapper_dict[key]
|
||||
return type.__new__(mcs, name, bases, attrs)
|
||||
|
||||
|
||||
class QlibLogger(metaclass=MetaLogger):
|
||||
@@ -48,7 +48,7 @@ class QlibLogger(metaclass=MetaLogger):
|
||||
return self.logger.__getattribute__(name)
|
||||
|
||||
|
||||
def get_module_logger(module_name, level: Optional[int] = None) -> logging.Logger:
|
||||
def get_module_logger(module_name, level: Optional[int] = None) -> QlibLogger:
|
||||
"""
|
||||
Get a logger for a specific module.
|
||||
|
||||
@@ -107,7 +107,7 @@ class TimeInspector:
|
||||
"""
|
||||
Get last time mark from stack, calculate time diff with current time, and log time diff and info.
|
||||
:param info: str
|
||||
Info that will be log into stdout.
|
||||
Info that will be logged into stdout.
|
||||
"""
|
||||
cost_time = time() - cls.time_marks.pop()
|
||||
cls.timer_logger.info("Time cost: {0:.3f}s | {1}".format(cost_time, info))
|
||||
@@ -146,6 +146,7 @@ def set_log_with_config(log_config: Dict[Text, Any]):
|
||||
|
||||
class LogFilter(logging.Filter):
|
||||
def __init__(self, param=None):
|
||||
super().__init__()
|
||||
self.param = param
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user