This article mainly introduces how to implement logview in python web mode. it involves Python's skills for operating Linux commands based on web modules and has some reference value, for more information about how to implement logview in python, see the following example. Share it with you for your reference. The details are as follows:
Here, we use Python to view logs through web, and use python's popen to execute the linux tail command.
Note: the web. py environment is required.
The code is as follows:
# Coding = utf8import webimport osurls = ('/', 'index') class index: def GET (self): command = 'tail-n100/var/log/tomcat6/catalina. out 'textist = OS. popen (command ). readlines () # result = 'last 100 lines log' for line in textlist: result = '% s \ n % s' % (result, line) return result # actually, you can directly return textline. if _ name _ = "_ main _": app = web. application (urls, globals () app. run ()
Modify the log file location in the program and run the following command on the linux command line:
The code is as follows:
Python logview. py 1234
1234 is the port you specified.
Browser access: http: // your IP: 1234
I hope this article will help you with Python programming.