Python web logview
原文:http://my.oschina.net/waterbear/blog/149857
用web方式查看日志的一个小东西,用python的popen执行了linux的tail命令来实现。
注意:需要web.py环境
#coding=utf8
import web
import os
urls = (
'/', 'index'
)
class index:
def GET(self):
command = 'tail -n100 /var/log/tomcat6/catalina.out'
textlist = os.popen(command).readlines()#执行linux命令的哦
result = '<h1>Last 100 lines log</h1>'
for line in textlist:
result = '%s\n%s'%(result,line)
return result#其实直接return textline也是可以哦
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
在程序中修改日志文件位置,linux命令行运行:
python logview.py 1234
1234就是你指定的端口了
浏览器访问:http://你的IP:1234