php output log
This article introduces the content of PHP output log, which has certain reference value. Now I share it with everyone. Friends in need can refer to it.
Reprinted from https ://www.cnblogs.com/yszr/p/8489433.html
error_log('The information you want to output', 3, 'E:\work\jiajiayue\Application\Api\Controller\1.txt') ;die;
How to use and configure the php error_log log
For PHP developers, once a product is put into use, the display_errors option should be turned off immediately to avoid being affected by these errors. The disclosed paths, database connections, data tables and other information were hacked. However, after any product is put into use, errors will inevitably occur, so how to record some error reports that are useful to developers? We can log error reports in separate text files. The recording of error logs can help developers or managers check whether there are problems with the system. If you need to write the error report in the program to the error log, just turn on the configuration directive log_errors in the PHP configuration file. Error reports will be logged to the log file of the web server by default, for example, to the error log file error.log of the Apache server. Of course, you can also record the error log to a specified file or send it to the system syslog. The details are as follows:
1. Use the specified file to record the error report log
Use The specified file records the error report log. Use the specified file to record the error report log. Use the specified file to record the error report log. If you use a specified file to record the error log, be sure to store this file outside the document root directory to reduce the risk of errors. to the possibility of attack. And the file must be written by the user who executes the PHP script (the owner of the Web server process). Assume that in the Linux operating system, the error.log file in the /usr/local/ directory is used as the error log file, and the Web server process user is set to have write permissions. Then in the PHP configuration file, set the value of the error_log directive to the absolute path of the error log file.
You need to make the following modifications to the configuration instructions in php.ini:
1. error_reporting = E_ALL ; Every error that occurs will be reported to PHP
2. display_errors = Off ; Do not display the above instruction All the error reports of the defined rules
3. Log_errors = on; Determine the location of the logs recorded
4. Log_errors_max_len = 1024; set the maximum length of each log. /php_error.log ;Specify the location of the log file where the generated error report is written
After the PHP configuration file is set as above, restart the web server. In this way, when executing any PHP script file, all error reports generated will not be displayed in the browser, but will be recorded in the error log /usr/local/error.log specified by you. In addition, not only can all errors that meet the rules defined by error_reporting be recorded, but also a user-defined error message can be sent using the error_log() function in PHP.
The prototype of this function is as follows:
1. bool error_log ( string message [, int message_type [, string destination [, string extra_headers]]] )
This function will send error information to the error log file of the Web server, a TCP server, or to a specified file. This function returns TRUE if successful and FALSE if failed. The first parameter message is required and is the error message to be sent. If only this parameter is used, the message will be sent at the location set in the configuration file php.ini. The second parameter message_type is an integer value: 0 means sending it to the log of the operating system; 1 uses PHP's Mail() function to send the message to an E-mail address, and the fourth parameter extra_headers will also be used; 2 Send the error message to the TCP server. At this time, the third parameter destination represents the destination IP and Port; 3. Save the information to the file destination.
If we take the problem of logging into the Oracle database as an example, the use of this function is as follows:
1. <?php 2. if(!Ora_Logon($username, $password)){ 3. error_log("Oracle数据库不可用!", 0); //将错误消息写入到操作系统日志中 4. } 5. if(!($foo=allocate_new_foo()){ 6. error_log("出现*烦了!", 1, ". mydomain.com"); //发送到管理员邮箱中 7. } 8. error_log("搞砸了!", 2, "localhost:5000"); //发送到本机对应5000端口的服务器中 9. error_log("搞砸了!", 3, "/usr/local/errors.log"); //发送到指定的文件中 10. ?>
2. The error message is recorded in the log of the operating system.
The error message is recorded in the log of the operating system. The error message is recorded in the log of the operating system. Error information recorded in the operating system log. Error reports can also be recorded in the operating system log, but log management is somewhat different between different operating systems. On Linux error statements will be sent to syslog, while on Windows errors will be sent to the event log. If you are not familiar with syslog, at least know that it is a UNIX-based logging tool that provides an API to record messages related to system and application execution. The Windows event log is actually the same as the UNIX syslog, and these logs can usually be viewed through Event Viewer. If you want to write error reports to the operating system log, you can set the value of the error_log directive to syslog in the configuration file.
The specific configuration instructions that need to be modified in php.ini are as follows:
##
1. error_reporting = E_ALL ;将会向PHP报告发生的每个错误 2. display_errors = Off ;不显示 满足上条指令所定义规则的所有错误报告 3. log_errors = On ;决定日志语句记录的位置 4. log_errors_max_len = 1024 ;设置每个日志项的最大长度 5. error_log = syslog ;指定产生的错误报告写入操作系统的日志里
In addition to general error output, PHP also allows sending customized messages to the system syslog. Although customized messages can also be sent to syslog through the error_log() function introduced earlier, PHP provides four dedicated functions for this feature that need to be used together.
are introduced as follows:
define_syslog_variables()
Must be used before using the three functions openlog(), syslog and closelog() Call this function first. Because when this function is called, it will initialize some necessary constants for the following three functions based on the current system environment.
openlog()
Open a connection to the logger in the current system to prepare for inserting log messages into the system. And insert the provided first string parameter into each log message. This function also needs to specify two parameters that will be used in the log context. You can refer to the official documentation for use.
syslog()
This function sends a customized message to the system log. Two required parameters are required. The first parameter customizes the priority of the message by specifying a constant. For example, LOG_WARNING represents a general warning, LOG_EMERG represents a serious problem that may indicate a system crash, and some other constants indicating severity can be used by referring to the official documentation. The second parameter is a customized message sent to the system log. You need to provide a message string or an error string provided by the PHP engine at runtime.
closelog()
This function is called after sending the customized message to the system log to close the log connection opened by the openlog() function.
If you have enabled the command to send customized messages to syslog in the configuration file, you can use the four functions introduced earlier to send a warning message to the system log. , and use the syslog parsing tool in the system to view and analyze the customized messages sent by the PHP program, as shown below:
1. 2. define_syslog_variables(); 3. openlog("PHP5", LOG_PID , LOG_USER); 4. syslog(LOG_WARNING, "警告报告向syslog中发送的演示, 警告时间:".date("Y/m/d H:i:s")); 5. closelog(); 6. ?>
Using Windows Taking the system as an example, by right-clicking "My Computer" and selecting the management option, then going to the system tools menu, selecting Event Viewer, and then finding the application option, you can see our customized warning message. The above code will generate a message similar to the following in the system's syslog file, which is part of the event:
1. PHP5[3084], a demonstration of warning reporting sent to syslog, warning Time: 2009/03/26 04:09:11.
Whether you use a specified file or syslog to record error logs depends on your Web server environment. If you have control over the web server, using syslog is ideal because you can use syslog parsing tools to view and analyze the logs. But if your website is running in a virtual host on a shared server, you can only use a separate text file to record error logs.
The above is the detailed content of php output log. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

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

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
