python-CSD-kursu/python-temel/log.dekorator.2.py

24 lines
393 B
Python
Raw Normal View History

2023-08-07 18:10:37 +03:00
import datetime
import time
def log(path):
file = open(path, 'w')
def bar(f):
def tar(*args, **kwargs):
dt = datetime.datetime.now()
print(dt)
file.write(str(dt) + '\n')
f(*args, **kwargs)
return tar
return bar
@log('log.txt')
def foo():
print('foo çağrıldı')
foo()
time.sleep(3)
foo()
time.sleep(2)
foo()