-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging_mod.py
More file actions
40 lines (27 loc) · 931 Bytes
/
logging_mod.py
File metadata and controls
40 lines (27 loc) · 931 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
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
from reusepatterns.singletones import SingletonByName
from time import time
class ConsoleWriter:
def write(self, text):
print(text)
class FileWriter:
def __init__(self, file_name):
self.file_name = file_name
def write(self, text):
with open(self.file_name, 'a', encoding='utf-8') as f:
f.write(f'{text}\n')
# Заметка, можно применить стратегию если добавить стратегию логирования
class Logger(metaclass=SingletonByName):
def __init__(self, name):
self.name = name
def log(self, text):
print('log--->', text)
# декоратор
def debug(func):
def inner(*args, **kwargs):
start = time()
result = func(*args, **kwargs)
end = time()
print('DEBUG-------->', func.__name__, end - start)
return result
return inner