Home > Article > Backend Development > Share the method of writing logs into syslog files in php
defines the saving location of logs generated by daemon, where daemon is the log type, and "*" represents all levels of The logs are placed in this file. The format is: facility. level -The path where the log file is saved, such as -/var/log/daemon.log level includes:
Then execute the command /etc/init.d/sysklogd restart or /etc/init.d/sysklogd reload to use The new configuration takes effect. Start testing the new log rules: 1. Enter the command
2. Execute the command
You can see the log information you wrote: Note: local4.info in syslog.conf represents that all logs of info level and above will be recorded here. At this point, the required logs have been set up in ubuntu. Now let’s start using syslog in php to write logs to syslog in ubuntu. The reference code is as follows: <?php //写日志到syslog openlog("Event1.0", LOG_PID | LOG_PERROR, LOG_LOCAL4); syslog($level, "LOG MESSAGE: " . $errinfo); closelog(); ?> Instructions: The first parameter of openlog is the log identifier, which is automatically added to the beginning of the log information to indicate what system wrote the log. Since we want to write the log to local4.info here, we need to use LOG_LOCAL4 as the third parameter, which represents the device information for writing the log. $level in syslog is the log level, including: LOG_EMERG system is unusable LOG_ALERT action must be taken immediately LOG_CRIT critical conditions LOG_ERR error conditions LOG_WARNING warning conditions LOG_NOTICE normal, but significant, condition LOG_INFO informational message LOG_DEBUG debug-level messageThe second parameter is the specific log content. Regarding the method of writing logs to syslog in PHP, I will introduce these. I hope it will be helpful to everyone. |