1 set_exception_handler(callback $exception_handler); //Exception capture custom handler function registration
1 set_error_handler(callback $error_handler); //Error capture custom handler function registration
1 register_shutdown_function(callback $callback); //Abnormal termination error capture handler function registration during program execution
<span>1</span> <span>set_exception_handler</span>(<span>array</span>("Myexception","exceptionHandler"<span>)); </span><span>2</span> <span>set_error_handler</span>(<span>array</span>("Myexception","errorHandler"<span>)); </span><span>3</span> <span>register_shutdown_function</span>(<span>array</span>("Myexception","shutdownHandler"));
<span>109</span> <span>/*</span><span>* </span><span>110</span> <span> * Attach the file write to logging. Multiple writers are supported. </span><span>111</span> <span>*/</span> <span>112</span> Kohana::<span>$log</span>->attach(<span>new</span> Log_File(APPPATH.'logs'));
This is to add a logging object to the log object. Pay attention to the two with olive color background. They are different class library instances. In kohana, the logging object is divided into two parts. The first part is The log object is used to maintain a list of logging objects. How to understand this? It is actually like a container, which contains one or more logging objects (this is the second part. These logging objects are the real source of the log object). Logging), and an array of error levels to be recorded for each object. When the error level is met, it will be recorded. If not, it will be omitted. Here is my own simplified logging method after renaming:
<span>1</span> self::<span>$log</span> = <span>Log</span>::<span>instance(); </span><span>2</span> self::<span>$log</span>->attach(<span>new</span> Logwriter("./data/debug"),<span>Log</span>::<span>DEBUG); </span><span>3</span> self::<span>$log</span>->attach(<span>new</span> Logwriter("./data/notice"),<span>Log</span>::NOTICE);
In order to better understand here, I named the "container" as Log and the recorded instance as Logwriter. You can see that I easily added two different log types at the program entrance. The first one is to record all Errors with error numbers smaller than Log::DEBUG (error levels higher than him) are recorded under the folder ./data/debug according to rules. The second one is errors with a recording level equal to or higher than Log::NOTICE. Of course You can also specify which errors are good in more detail. Just pass the array. This is what I think is convenient and fast. We can add error logs and divide them into different log directories according to needs. Look at the picture below. Helps to understand:
The relationship between log and logwriter
You will see from the picture above that Log is a container that contains different specific logwriter objects. Each object may record different information. When the error information is written to the file, each Logwriter will be run. For example, see if you want to record the error in error message. If the level in error message is not included in Logwriter, it will be ignored.
How does this part cooperate with the first part? In fact, it is very simple. When an exception is caught by exception, it will be called to add an error message (including error location, error code, error message, etc.) to the errormessage array in the Log container, and then write this information to the file after the program ends. , please note here, maybe when you read the kohana code, you find that there is no obvious direct writing to the log. Kohana is better optimized here, because multiple errors may occur in one execution of php. If an error occurs, you Just record it once, which will take up extra IO and time before the program returns, so kohana's approach is to store all errors, exceptions, and logs in Log::$errormessage by default, and talk about the Log in it when instantiating it. The writer operation registers register_shutdown_function. The function of this function is to execute it after the program terminates abnormally or the execution is completed. It is also used in the first part above, so that the log record will not have a big impact on the execution of this PHP.
3. Example summary
At this point you should have an overview of the log system, and you can already write a "log system" for use. Let's take a look at the example of my "log system". This is the github address, which contains code and examples. You can take a look if you need to.
https://github.com/AizuYan/phplog.git
The copyright of this article belongs to the author (luluyrt@163.com) and the blog park. Any form of reprinting is prohibited without the author's consent. After reprinting the article, the author and the original text link must be given in an obvious position on the article page, otherwise legal liability will be pursued. s right.
The above has introduced the logging system in the PHP framework, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

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