跟踪几个uwsgi日志文件并在错误发生时发送电子邮件。
tail-uwsgi-log的Python项目详细描述
这个包裹是做什么用的
在您的服务器上跟踪日志文件,并在发生错误时通过电子邮件报告。在
默认情况下,regex模式是为默认的uwsgi日志设置的。在
安装
pip install tail_uwsgi_log
使用
^{pr2}$配置
配置文件提供了向tail发送电子邮件和日志文件所需的信息。在
例如:
; section name startswith 'log' would be interpreted as logfile config[log-myapp1]; log file pathfilepath=your_log_filepath; wait_time for tail command, the thread will sleep and wait; the wait_time should be small if the server is busy and generates log lines quicklywait_time=0.5; the regex pattern to read the log line, the line doesn't match this regex will be recorded as innormalpattern=; mail settingsmail_recipients=example1@example.com, example2@example.commail_host=smtp.qq.commail_port=465mail_sender=your_email_addressmail_password=your_password
为了同时跟踪多个日志文件,我们可以在配置文件上设置多个节,节名应该以“log”开头。在
对于邮件设置,我们可以使用名为“mail”的部分来设置默认值。如果未在日志部分设置,则使用默认值。在
例如:
[log-myapp1]filepath=your_log_filepath1wait_time=0.5pattern=mail_recipients=example1@example.com, example2@example.com[log-myapp2]filepath=your_log_filepath2wait_time=1pattern=mail_recipients=example3@example.com, example4@example.com[mail]mail_host=smtp.qq.commail_port=465mail_sender=your_email_addressmail_password=your_password
与logline匹配的默认regex模式用于默认的uwsgi日志,即:
pattern=r'''\]\ (?P<ip>.*?)\ (.*)\ {.*?}\ \[(?P<datetime>.*?)\]\ (?P<request_method>POST|GET|DELETE|PUT|PATCH)\s (?P<request_uri>[^ ]*?)\ =>\ generated\ (?:.*?)\ in\ (?P<resp_msecs>\d+)\ msecs\s \(HTTP/[\d.]+\ (?P<resp_status>\d+)\)'''
模式中的'resp\'status'很重要,它将用作信号。在
当resp的状态为500时,将发送一封电子邮件,其中记录了之前记录的所有非正常日志行。在
- 项目
标签: