如何在 Tornado 中管理 nohup.out 文件? [英] How to manage nohup.out file in Tornado?

查看:26
本文介绍了如何在 Tornado 中管理 nohup.out 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Tornado 构建了一个 Web 服务,它日夜提供服务.我使用命令启动我的服务:

I built a web service using tornado and it serves days and nights. I used the command to start my service:

nohup python my_service.py &

服务日志能够写入nohup.out.但是,随着时间的推移,文件会变得更大.我想知道如何更方便地管理它?比如说,使用自动方法生成具有适当名称和大小的日志文件?如:

The service log is able to write to nohup.out. However, the file becomes bigger as time goes. I want to know how can I manage it more conveniently? For saying, using an automatic method to generate the log files with proper names and size? Such as:

service_log_1.txt
service_log_2.txt
service_log_3.txt
...

谢谢.

推荐答案

@jujaro 的回答很有帮助,我在我的网络服务中尝试了 logging 模块.但是,在 Tornado 中使用日志记录仍有一些限制.请参阅其他问题问.

@jujaro 's answer is quite helpful and I tried logging module in my web service. However, there are still some restrictions to use logging in Tornado. See the other question asked.

结果,我尝试在linux中使用crontab在午夜创建一个cron作业(在linux shell中使用crontab -e):

As a result, I tried crontab in linux to create a cron job at midnight (use crontab -e in linux shell):

59 23 * * * source /home/zfz/cleanlog.sh

这个 cron 作业在每天 23:59 启动我的脚本 cleanlog.sh.

This cron job launches my script cleanlog.sh at 23:59 everyday.

clean.sh的内容:

fn=$(date +%F_service_log.out)
cat /home/zfz/nohup.out >> "/home/zfz/log/$fn"
echo '' > /home/zfz/nohup.out

此脚本创建一个带有当天日期的日志文件,并且 echo '' 清除 nohup.out 以防它变大.这是我现在从 nohup.out 中分离出来的日志文件:

This script creates a log file with the date of the day ,and echo '' clears the nohup.out in case it grows to large. Here are my log files split from nohup.out by now:

-rw-r--r-- 1 zfz zfz  54474342 May 22 23:59 2013-05-22_service_log.out
-rw-r--r-- 1 zfz zfz  23481121 May 23 23:59 2013-05-23_service_log.out

这篇关于如何在 Tornado 中管理 nohup.out 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆