Home Backend Development PHP Tutorial Analyze how php writes logs into syslog_PHP tutorial

Analyze how php writes logs into syslog_PHP tutorial

Jul 21, 2016 pm 03:02 PM
php syslog for how Will us log Purpose system parse Operation and maintenance

In order to facilitate operation and maintenance when working on projects, we often need to write system logs to the system syslog. Below we will introduce the operation of php on syslog under Linux:
Configuration in Linux syslog
In Linux, facilities (devices) have the following types:
AUTH common security/authorization messages
AUTHPRIV private security/authorization messages
CRON timer process
DAEMON daemon
KERN kernel message
LOCAL0... LOCAL7 local application, not supported on windows
LPR line printer
MAIL mail service
NEWS news service
SYSLOG by Messages generated within syslogd
USER General user-level information
UUCP UUCP subsystem
Log in to the Linux system, enter the /etc directory, enter:

Copy the code The code is as follows:

vim syslog.conf

Open the syslog configuration file
Here, you can see All configuration information to syslog, here defines the conditions used to store logs for each log type mentioned in the previous section, such as:
daemon.* -/var/log/daemon.log
definition Specifies the storage location of the logs generated by the daemon, where daemon is the log type, and "*" means that all levels of 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:
emerg - the system is unavailable
alert - conditions that need to be modified immediately
crit - error conditions that prevent certain tools or subsystem functions from being implemented
err - error conditions that prevent tools or some subsystem functions from being implemented
warning - early warning information
notice - important Ordinary conditions
info - informational messages
debug - does not contain function conditions or other information about the problem
none - no importance level, usually used for debugging
* All levels except none
Next 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 makes the new configuration take effect. Now we can test the new log rules:
1. Enter the command logger -p local4.info "my test log" 2. Execute the command tail /var/log/event_log.log

You can see the log information you wrote:

Note: local4.info in syslog.conf represents all Logs of info level and above will be recorded hereok, now we have set up the logs we need in ubuntu, now we use syslog in php to write the logs to syslog in ubuntu.

The following is the php code directly:
Copy the code The code is as follows:
openlog(" Event1.0", LOG_PID | LOG_PERROR, LOG_LOCAL4);
syslog($level, "LOG MESSAGE: " . $errinfo);
closelog();

The above methods Please check the PHP API for specific usage. The specific usage will not be described here.
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, the third parameter needs to use LOG_LOCAL4, 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.

http://www.bkjia.com/PHPjc/327942.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327942.htmlTechArticleIn order to facilitate operation and maintenance when doing projects, we often need to write system logs to the system syslog. Below we Let me introduce the operation of syslog by PHP under Linux: Configure in Linux...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

See all articles