-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlog_ex.py
55 lines (42 loc) · 1.31 KB
/
log_ex.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
45
46
47
48
49
50
51
52
53
54
55
import logstash
import logging.config
import ConfigParser
import os
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__)))
logging_conf_path = os.path.normpath(os.path.join(root_path, 'logging.conf'))
logging.config.fileConfig(logging_conf_path)
logger = logging.getLogger("zt")
logger.addHandler(logstash.LogstashHandler('115.28.102.142', 55514))
config = ConfigParser.ConfigParser()
extra = {
# 'host': 'unknow',
'program': 'jingdong',
'device_id': 'unkown'
}
try:
private_conf_file = os.path.normpath(os.path.join(root_path, 'private.conf'))
config.readfp(open(private_conf_file, "r"))
# extra['host'] = config.get("log", "host")
extra['device_id'] = config.get("log", "device_id")
except Exception, e:
pass
def debug(msg, key='', program=''):
extra['key'] = key
if program:
extra['program'] = program
logger.debug(msg, extra=extra)
def info(msg, key='', program=''):
extra['key'] = key
if program:
extra['program'] = program
logger.info(msg, extra=extra)
def warn(msg, key='', program=''):
extra['key'] = key
if program:
extra['program'] = program
logger.warn(msg, extra=extra)
def error(msg, key='', program=''):
extra['key'] = key
if program:
extra['program'] = program
logger.error(msg, extra=extra)