Search code examples
phpcentos6syslogsyslog-ng

How to specify a php log file using syslog-ng


Within my PHP script, I have a line printing output to syslog, much like the one below:

syslog(LOG_INFO, "Writing log info to syslog");

By default, it prints output to /var/log/messages. Is there anyway to change the output file to be something different? I am using syslog-ng and a CentOS 6 server.


Solution

  • This has nothing (really) to do with PHP. You're not wring to a "file" - you're sending your log entry to the syslog daemon, "here's something for the log named LOG_INFO", and the syslog daemon decides where that should go.

    If you want to target a specific file, you'd have to set a LOG_XXXX target to point to that file in the syslog configuration - you can't have PHP tell syslog which file it should use directly.

    If you do want specific file targeting, then use error_log() instead, where you CAN specify the filename to log to.