Python processing logs

Source: Internet
Author: User
1. Read the log file from the server (\ URL \ server_errors.log)
The log format we need is: Date and Time level, such as 23:33:28, 140 Error
There are two methods:
First, use readlines () to loop through a text file
Second, use the fileinput module to loop through a text file
2. Match the regular expression at the end of the log to obtain the appropriate log information.
Currently, we only need to read the log information with the log level of error between two date regular expressions.
3. Log collection center
Send Logs containing error information to relevant personnel.
The basic form of log, in order to prevent the log is too large, every hour will re-write the log file, and between the file is renamed to the server_errors.log.yyyy-dd-mm-nn, where NN is the serial number, from 00 to 23
Main architecture:
1. Some basic settings, such as the server address and Log Level
2. logparser class
2.1 _ init _ () method, initialization
2.2 getfilelist: Mainly reads the list of all log files today
2.3 parselog: mainly analyzes and stores useful log information.
2.4 sendlog: Send the log to relevant personnel

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.