UWSGI logrotation(UWSGI logrotation)

2019-10-23 22:39发布

我已经运行uwsgi服务器。 我需要记录日常和文件大小的基于日志旋转旋转。

uwsgi配置:

# file: /etc/init/uwsgi.conf
description "uWSGI starter"

start on (local-filesystems and runlevel [2345])
stop on runlevel [016]

respawn

# home - is the path to our virtualenv directory
# pythonpath - the path to our django application
# module - the wsgi handler python script

exec /home/testuser/virtual_environments/teatapp/bin/uwsgi \
--uid testuser \
--home /home/testuser/virtual_environments/teatapp \
--pythonpath /home/testuser/sci-github/teatapp\
--socket /tmp/uwsgi.sock \
--chmod-socket \
--module wsgi \
--logdate \
--optimize 2 \
--processes 2 \
--master \
--logto /var/log/uwsgi/uwsgi.log

logrotate的配置:

# file : /etc/logrotate.conf

"/var/log/uwsgi/*.log" {
    copytruncate
    daily
    maxsize 5k
    dateext
    rotate 5
    compress
    missingok
    create 777 root root
}

但是日志旋转不工作,请给予解决的,如果在logrotaion.conf任何错误的配置。

Answer 1:

there is logrotation in uwsgi, based on the log file size, for example (uwsgi.ini directive):

log-maxsize = 100000

if you want to use logrotated, you have to restart uwsgi (logrotate directives):

postrotate
           stop uwsgi
           start uwsgi
endscript


Answer 2:

它不需要重启uwsgi服务,如果您使用copytruncate在选项logrotate文件(如添马舰说明)。

但问题可能是你忘了启用logrotatecron 。 请确保你有一个条目/etc/cron.dailylogrotate



Answer 3:

只要把这个在你的uwsgi配置文件:

守护进程= /无功/日志/ uwsgi / uwsgi- @(EXEC://日期+ %%ý - %%米 - %% d)的.log

这将每天创建日志,但要小心,如果你使用的是掌握我们的emperror不守护进程。 这时如果日志大,你可以用attatched到cron来清理文件夹中的脚本控制它。



文章来源: UWSGI logrotation