Open tahajahangir opened 10 years ago
Having the same issue with 'touch-logreopen' option. The option only reopens log filed defined with 'logto' option.
request logging only uses pluggable loggers, so "basic file-logging" procedure cannot work. Each plugin has its features, and, as an example, "reopening" is not meaningful for the vast majority of them. You could improve the logfile plugin to support reopening, or you can use the logpipe plugin to use (again as an example) a tool like this: http://httpd.apache.org/docs/2.2/programs/rotatelogs.html
Try to describe your specific scenario, maybe there is a better solution or approach to follow
I am using linux bundled 'logrotate' to rotate the log file of req-logger. I do not want to reload uWSGI after each rotation and thus trying to use the touch-logreopen option. BTW, I am using 'copytruncate' option of 'logrotate' as a workaround right now. And, I will later use chain reload of uWSGI instead of 'copytruncate' if the logfile plugin is not going to support touch-logreopen.
FYI, my logrotate config right now:
/var/log/uwsgi/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
create 644 www-data www-data
}
@unbit, is there a better alternative to 'copytruncate' other than uWSGI chain reload?
I would have suggested the 'copytruncate' approach, but i have to suppose it is problematic for you (huge logfile size and/or copying it requires ages, slow I/O ...). @xrmx implemented log-rotation in the file logger, but (being based on size and not time) i suppose it is suboptimal too. The only solution i could think of is improving https://github.com/unbit/uwsgi/blob/master/plugins/logfile/logfile.c to reopen logs on specific events (like on a master-fifo command). Or to improve it to periodically (like once every 30 seconds) check if the inode of the logfile changed, and automatically reopen it when happens.
It looks like the logfile plugin already supports rotating to a backup file based on a maxsize (see the 'backupname' and 'maxsize' options in https://github.com/unbit/uwsgi/blob/master/plugins/logfile/logfile.c). You can then setup logrotate to rotate the backup file. If logrotate runs frequently enough, it should be able to get the backup file out of the way before uwsgi does the next rotation.
Well, I think it's better to use syslog instead of logging to file directly. No more reload / reopen headache. So, logrotate now manages the log file produced by syslog instead of uwsgi :)
fyi - https://hynek.me/articles/taking-some-pain-out-of-python-logging/
Anyone bumping here check this commit https://github.com/xrmx/uwsgi/commit/79bbed9cbc79bb2e4017e5ee38c793a53954bab6 that explains how to actually use maxsize and backupname arguments.
Copy-paste for the lazy:
logger = staticlogger file:logfile=%dstatic.log,backupname=%dstatic.log.old,maxsize=1500
My problem is that logfile plugin doesn't apparently obey umask
directive? Would that need separate support from the plugin as well?
Touching the file specified by
touch-reopen
option does not reopen the request log file (specified byreq-logger
option).