-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
38 lines (31 loc) · 1.03 KB
/
logger.py
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
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
# pylint: disable=C0103
"""Configuration file"""
import logging
import time
from functools import wraps
detailed_format = "%(filename)s [LINE:%(lineno)03d] [%(asctime)s] %(levelname)-s %(funcName)s() %(message)s"
short_format = "[%(asctime)s] %(message)s"
logging.basicConfig(
format=detailed_format, level=logging.INFO, datefmt="%y-%m-%d %H:%M:%S"
)
log = logging.getLogger(__name__)
def logging_time(func):
@wraps(func)
def wrapper(*args, **kwargs):
start_time = time.time()
log.info(
f"{func.__name__} - Start time:"
f" {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(start_time))}"
)
result = func(*args, **kwargs)
end_time = time.time()
log.info(
f"{func.__name__} - End time:"
f" {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(end_time))}"
)
log.info(
f"{func.__name__} - Duration:" f" {end_time - start_time:.2f} seconds\n"
)
return result
return wrapper