forked from dunossauro/live-de-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_pdb.py
More file actions
41 lines (32 loc) · 1021 Bytes
/
Copy pathlog_pdb.py
File metadata and controls
41 lines (32 loc) · 1021 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
41
from logging import getLogger, basicConfig, DEBUG
from sys import exc_info
from collections import deque
from pdb import post_mortem
basicConfig(filename='test.log',
filemode='w',
level=DEBUG)
log = getLogger(__name__)
log.info('teste2')
log.info('teste3')
log.info('teste4')
log.info('teste1000')
def debug(debug=False):
def tail_log(func):
def exectute_func(*args):
try:
func(*args)
except Exception as error:
log.info('{} args:{} error:{}'.format(func.__name__,
args,
error))
if debug:
for line in deque(open('test.log'), 10):
print(line)
post_mortem(exc_info()[2])
return exectute_func
return tail_log
@debug(True)
def div(x, y):
log.info('Entrei na função {}'.format(div.__name__))
return x / y
div(2, 0)