跟踪几个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时,将发送一封电子邮件,其中记录了之前记录的所有非正常日志行。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
插入表达式以完成JAVA语句块时出现语法错误   在linkedlist中的特定节点后插入java   java如何将参数传递给安卓 junit测试(参数化测试)   java在运行时将数据添加到片段中的RecyclerView,在该片段中,数据是在单独的片段中创建的   java apache CsrfPreventionFilter和404错误   java Ask是安卓 6.0的多重权限   java将字符串解析为Time并插入mysqldatabase   java扩展MyBatis映射器接口可能导致异常   java SparkSql不支持日期格式   在java中剪切字符串的一部分   将Java lambda的结果分配给字段   在Java中解析OCL?   java解析json到安卓中活动中的对象   用于时区转换的JavaAPI   在Oracle上建立与ESRI geodatabase直接连接的java在未处于调试模式时挂起   拆分文件时出错。使用Java8的xml文件   java eclipse jsp无颜色、代码完成和错误检测   java spring kafka侦听器在错误的位置查找ContainerProperty   java Springboot应用程序@EnableConfigServer无法在Eclipse中解析   当尝试使用ConstraintLayout将java视图添加到同一行时,java视图会被截断