log dekoratör

This commit is contained in:
Mert Gör 🇹🇷 2023-08-07 18:10:37 +03:00
parent 193f00dc08
commit f7c8912b2a
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,23 @@
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()

3
python-temel/log.txt Normal file
View File

@ -0,0 +1,3 @@
2023-08-07 18:09:52.933092
2023-08-07 18:09:55.951920
2023-08-07 18:09:57.952992