mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-13 15:56:57 +08:00
Update handler interface round2
This commit is contained in:
23
qlib/log.py
23
qlib/log.py
@@ -8,6 +8,7 @@ import os
|
||||
import re
|
||||
from logging import config as logging_config
|
||||
from time import time
|
||||
from contextlib import contextmanager
|
||||
|
||||
from .config import C
|
||||
|
||||
@@ -79,6 +80,28 @@ class TimeInspector(object):
|
||||
cost_time = time() - cls.time_marks.pop()
|
||||
cls.timer_logger.info("Time cost: {0:.5f} | {1}".format(cost_time, info))
|
||||
|
||||
@contextmanager
|
||||
@classmethod
|
||||
def logt(cls, name="", show_start=False):
|
||||
"""logt.
|
||||
Log the time of the inside code
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name :
|
||||
name
|
||||
show_start :
|
||||
show_start
|
||||
"""
|
||||
if show_start:
|
||||
cls.timer_logger.info(f"Begin {name}")
|
||||
cls.set_time_mark()
|
||||
try:
|
||||
yield None
|
||||
finally:
|
||||
pass
|
||||
cls.log_cost_time()
|
||||
|
||||
|
||||
def set_log_with_config(log_config: dict):
|
||||
"""set log with config
|
||||
|
||||
Reference in New Issue
Block a user