Syslog dumps data into a singular log file. A lot of system services, even the kernel as you pointed out, dumps to syslog, and by extension, the same log file.
If you want to take advantage of your own personal log file, you'll need to use filesystem IO functions.
Example:
<?php
function writeLog($message) {
$handle = fopen('/var/log/project1/myproject1.log', 'a');
$line = '[' . date('Y-m-d H:i:s T') . '] ' . $message . "\n";
fwrite($handle, $line);
fclose($handle);
}
You should take care to make sure you don't fopen()
and then subsequently fclose()
a lot, since that will severely slow down your code. You should only fopen()
when you need to write/read, and then leave the file handle open until your PHP code exits (or let PHP do garbage collection for you).
You'll also need to make sure your web server has sufficient privileges to write to the /var/log/project1/
directory, or at the very least, append/write access to the filename specified. This includes making sure SELinux is happy if you have it enabled.
As a bonus, you could throw your custom log file into logrotate daemon's config and have your logs automatically rotated, compressed, archived, and whatnot.