log dekoratör
This commit is contained in:
parent
193f00dc08
commit
f7c8912b2a
2 changed files with 26 additions and 0 deletions
23
python-temel/log.dekorator.2.py
Normal file
23
python-temel/log.dekorator.2.py
Normal 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
3
python-temel/log.txt
Normal 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
|
Loading…
Reference in a new issue