[FASTCGI] save a log

Doru Georgescu headset001 at yahoo.com
Mon Sep 6 03:55:02 EDT 2010


Aron Szabo and Matthew Weigel: thank you for your answers. 

The program example of Aron Szabo was helpful, because I did not know about those specialized functions. I added some configuration details below, for reference. 

I am not sure if fflush(NULL); is required. When I test the program without fflush and I follow it in real time it all works fine, but still I believe that some records are missing. 

Matthew Weigel: not only that someone could write over the log file, if it gets application's user permissions, but, according to the Apache site, it could write a link over the log file, and this way the application would write over any arbitrary file on the system. 

Visit my application on 93.114.104.61, Firefox only, server is not always up. 

===================================================================

Configuration required to log your own application using system logging facilities: 

I added this: 
local6.=info -/var/log/apache2/myapp.log
at the end of /etc/syslog.conf, in order to log myapp.fcgi. 
Now all messages were written in /var/log/messages and in /var/log/syslog also; I discovered this with grep on all /var/log. Consequently, I added: 
;local6.!=info
to each selector in /etc/syslog.conf which contained myapp.log: 
*.*;auth,authpriv.none;local6.!=info            -/var/log/syslog
and: 
*.=info;*.=notice;*.=warn;\
        auth,authpriv.none;\
        cron,daemon.none;\
        mail,news.none;local6.!=info            -/var/log/messages
then: 
sudo /etc/init.d/sysklogd restart
Log rotation of /var/log/apache2/myapp.log takes place by default as a result of /etc/logrotate.d/apache2: 

/var/log/apache2/*.log {
        weekly
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        postrotate
                if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
                        /etc/init.d/apache2 reload > /dev/null
                fi
        endscript
}


The call: 
#include <syslog.h>
syslog(LOG_LOCAL6|LOG_INFO, "new n= %d;\n", count);

/var/log/apache2/myapp.log has been created automatically with the correct permissions. 








      


More information about the FastCGI-developers mailing list