Share the method of writing logs into syslog files in php

WBOY
Release: 2016-07-25 08:58:13
Original
858 people have browsed it
  1. daemon.* -/var/log/daemon.log
Copy code

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:

  1. local4.info -/var/log/
Copy the code

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

  1. logger -p local4.info " my test log"
Copy the code

2. Execute the command

  1. tail /var/log/event_log.log
Copy the code

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();
?>
Copy after login

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 message

The 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.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!