PHP writes the log into a syslog file by sharing the method

Source: Internet
Author: User
Tags syslog
    1. Daemon.*-/var/log/daemon.log
Copy Code

Defines the location where logs generated by Daemon are saved, where daemon is the log type, and "*" means that all levels of logs are placed in the file. The format is: facility. Level-the path where log files are saved, such as-/var/log/daemon.loglevel include:

    1. Local4.info-/var/log/
Copy Code

Next, execute the command/etc/init.d/sysklogd restart or/etc/init.d/sysklogd reload make the new configuration effective.

Start testing the new log rule: 1, enter the command

    1. Logger-p local4.info "My test Log"
Copy Code

2, execute command

    1. Tail/var/log/event_log.log
Copy Code

You can see the log information you wrote: Note: syslog.conf local4.info represents all info levels and the above logs are recorded here.

In this, the required logs have been set up in Ubuntu.

The following starts using Syslog in PHP to write the logs to the syslog in Ubuntu. The reference code is as follows:

 
      

Note: The first parameter of Openlog, which is the log ID, is automatically added to the beginning of the log information to indicate what the system writes to the log. Because here you want to write the log to Local4.info, the third parameter needs to use LOG_LOCAL4, which represents the device information written to the log. The $level in the syslog is the log level, which includes:

Log_emerg system is Unusablelog_alert action must be taken Immediatelylog_crit critical conditionslog_err error conditions Log_warning WARNING Conditionslog_notice Normal, but significant, conditionlog_info informational Messagelog_debug Debug-level message

The second parameter is a specific log content.

About PHP to write logs to the Syslog method, the introduction of these bar, I hope to be helpful to everyone.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.