-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
72 lines (63 loc) · 1.73 KB
/
logger.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import logging
import logging.config
'''
logging.config.dictConfig({
'version': 1,
'disable_existing_loggers': False, # this fixes the problem
'formatters': {
'standard': {
'format': '%(asctime)s %(name)-12s %(lineno)s %(levelname)-8s %(message)s'
},
},
'handlers': {
'default': {
'level':'DEBUG',
'class':'logging.StreamHandler',
},
},
'loggers': {
'': {
'handlers': ['default'],
'level': 'DEBUG',
'propagate': True
}
}
})
'''
def LoggerHandler(name):
'''
Prints the logs of Crawling
'''
logger = logging.getLogger(name)
#handler = logging.FileHandler('crawling.log',mode='w')
handler = logging.StreamHandler()
formatter = logging.Formatter(
'%(asctime)s %(name)-12s %(lineno)s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
return logger
def printRequest():
path = "/home/deepak/programs/proxy/requests.txt"
data = ""
try:
f = open(path, "r")
data = f.readlines()
data = ''.join(data)
except Exception as e:
print e
if data.find("HEADEREND")!=-1:
data = data.strip("HEADEREND")
headers = data.split("HEADEREND")
header = headers[0].strip()
return header
#print headers[0].split('\n')
else:
data = data.strip("RESPONSEHEADERS")
headers = data.split("RESPONSEHEADERS")
header = headers[0].strip()
return header
#print headers[0].split('\n')
def clearContent():
path = "/home/deepak/programs/proxy/requests.txt"
f = open(path, "w")