-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggerTest.py
44 lines (29 loc) · 859 Bytes
/
loggerTest.py
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
42
43
44
import logging
import sys
import json
class MyHandler(logging.Handler):
'A handler'
def emit(self, record):
print record.getMessage()
print 'handler got:', self.format(record)
formatter = logging.Formatter('%(name)s:%(levelname)s:%(asctime)s: %(message)s')
basename = 'HELLO'
json_data = json.dumps({'max': 100, 'done': 50})
logging.LogRecord
logger = logging.getLogger(basename)
logger1 = logging.getLogger(basename + '.logger1')
logger2 = logging.getLogger(basename + 'logger2')
handler = MyHandler()
logger.setLevel(logging.INFO)
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
try:
raise Exception, 'just for the heck of it'
except:
print sys.exc_info()
logger.exception('yeah')
logger.info(json_data)
logger1.info('hello1')
logger2.info('hello2')
print 'done'