Parsing PHP How to write logs into the syslog_php tutorial

Source: Internet
Author: User
Tags openlog syslog
In order to facilitate the operation of the project, we often need to write the system log system syslog, below we introduce, in the Linux The following PHP operation for Syslog:
Configuring Syslog in Linux
in Linux, facility (devices) have the following types:
AUTH General Security/authorization messages
Authpriv Private Security/authorization messages
CRON Timer Process
DAEMON Daemon Process
KERN kernel messages
LOCAL0 ... LOCAL7 local apps, not supported on Windows
LPR Line-Printer
Mail messaging Service
News press Service
SYSLOG messages generated internally by SYSLOGD
User-level information common to users
UUCP UUCP Subsystem
Login to the Linux system, enter/etc directory, enter:
Copy CodeThe code is as follows:
Vim syslog.conf

Open a syslog configuration file
Here you can see all the configuration information for the syslog, which defines the conditions used to store logs for each type of log mentioned in the previous section, such as:
Daemon.*-/var/log/daemon.log
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 the log file is saved, such as-/var/log/daemon.log
Level includes:
Emerg-The system is not available
Alert-conditions that require immediate modification
Crit-Error conditions that prevent some tool or subsystem functionality from being implemented
Err-Error condition implemented by block tool or partial functionality of some subsystems
Warning-Alert information
Notice-General conditions of importance
Info-messages that provide information
Debug-Additional information that does not contain a function condition or problem
None-no critical level, usually used for troubleshooting
* All levels, except none
Below we define a log rule for our own device in the configuration file: Local4.info-/var/log/
Next execute the command/etc/init.d/sysklogd restart or/etc/init.d/sysklogd reload make the new configuration take effect, below I we can test the new log rules:
1. Enter command logger-p local4.info "My test Log"
2. Execute Command tail/var/log/event_log.log
You can see the log information you wrote:
Note:Syslog.conf Local4.info represents all info levels and above logs are recorded here.
OK, so now that we've set up the logs we need in Ubuntu, we're going to use syslog in PHP to write the logs to the syslog in Ubuntu.
directly below the PHP code:
Copy CodeThe code is as follows:
Openlog ("Event1.0", Log_pid | Log_perror, LOG_LOCAL4);
Syslog ($level, "LOG MESSAGE:". $errinfo);
Closelog ();

The specific usage of the above methods please check the PHP API, the specific usage is not here to repeat.
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.
Since we 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 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 a specific log content.

http://www.bkjia.com/PHPjc/327942.html www.bkjia.com true http://www.bkjia.com/PHPjc/327942.html techarticle in order to facilitate the operation of the project, we often need to write system log system syslog, below we introduce, under Linux PHP to syslog operation: In Linux configuration ...

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