How to implement logview in the web mode using python

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.