-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeLogger.py
More file actions
30 lines (23 loc) · 767 Bytes
/
Copy pathTimeLogger.py
File metadata and controls
30 lines (23 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-
# @Time : 2021/7/18 23:47
# @Author : Jinhang
# @File : TimeLogger.py
from datetime import datetime
import logging
class TimeLogger:
def __init__(self):
self._last_time = None
def info(self, msg="", start=False):
indent_string = ''
logging.info(indent_string + msg)
current_time = datetime.now()
if start:
self._last_time = current_time
else:
duration = current_time - self._last_time
duration = int(duration.total_seconds() * 1000)
logging.info(indent_string + 'Duration: {} ms'.format(duration))
# @staticmethod
def debug(self, msg=""):
indent_string = ' ' * 4
logging.debug(indent_string + msg)