-
Notifications
You must be signed in to change notification settings - Fork 0
/
logwatcher.py
26 lines (25 loc) · 1.11 KB
/
logwatcher.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
import os
import subprocess as sub
from pygments.console import colorize
logs={'nginx_access_log':'/var/log/nginx/access.log','nginx_error_log':'/var/log/nginx/error.log','uwsgi_log':'/var/log/uwsgi/app/uwsgi.log'}
log=[]
index=[]
def test_log():
for item in logs:
log.append(logs[item])
index.append(item)
try:
while True:
acc_ng,err=sub.Popen(['tail','-1',log[0]],stdout=sub.PIPE,stderr=sub.PIPE).communicate()
err_ng,err=sub.Popen(['tail','-1',log[1]],stdout=sub.PIPE,stderr=sub.PIPE).communicate()
acc_uw,err=sub.Popen(['tail','-1',log[2]],stdout=sub.PIPE,stderr=sub.PIPE).communicate()
print index[0],"______________________________________________________________"
print colorize('red',acc_ng)
print index[1],"______________________________________________________________"
print colorize('blue',err_ng)
print index[2],"______________________________________________________________"
print colorize('green',acc_uw)
except KeyboardInterrupt:
pass
if __name__=='__main__':
test_log()