LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Individual log files using syslog (https://www.linuxquestions.org/questions/linux-newbie-8/individual-log-files-using-syslog-4175524790/)

NotionCommotion 11-08-2014 09:46 AM

Individual log files using syslog
 
I am running Centos/Apache with PHP 5.5.14, and am using syslog to write to a log file as follows:

syslog(LOG_INFO,'Some message');

The logs are being written to /var/log/messages and look like "Aug 10 15:48:16 devserver httpd: Some message", however, the log file is also cluttered with a bunch of logs that look like "Aug 10 15:48:21 devserver kernel: usb 1-1.2: USB disconnect, device number 83".

How do make PHP send logs to its own dedicated log file?

Note that I don't think this is a PHP question, but a syslog question. I also don't wish to create my own PHP version log writer, but use syslog.

Thanks

NotionCommotion 11-08-2014 10:52 AM

I've been reading a bit about syslog. Evidently, the service can be started/stopped using /etc/init.d/syslog, but my server doesn't seem to have that service. Furthermore, it could be configured using /etc/syslog.conf, but I also don't have that file. It appears that Centos does it differently. Looks like I should use rsyslog, right?

The logs I care about all include httpd. For instance:
Code:

Aug 10 15:48:16 devserver httpd: Some message
Would I be able to just put those logs in a different log file?

NotionCommotion 11-08-2014 11:25 AM

Okay, maybe I have a solution. Edit rsyslog.conf and add the following.
Code:

local0.* /var/log/php.log
Note that I did NOT remove local0 from also going to /var/log/messages. For instance, I did not add the following:
Code:

*.info;mail.none;authpriv.none;cron.none;local0.none /var/log/messages
It is bad practice to allow messages to go to two logs?

I now log this way:
Code:

openlog('myapplication', LOG_NDELAY, LOG_LOCAL0);
syslog(LOG_INFO, "Log to myapplication LOG_LOCAL0");

I guess I am good, but if anything sticks out as being wrong, please advise.


All times are GMT -5. The time now is 05:17 PM.