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