Home PHP Framework YII How to manually generate error logs in Yii

How to manually generate error logs in Yii

Dec 10, 2020 pm 04:48 PM
yii error log

How to manually generate error logs in Yii

The specific method is as follows:

First configure the error method and modify the errorHandler parameters

(Related recommendations: yii framework)

Under config/web, the default is the error method under the site controller

'errorHandler' => [
            'errorAction' => 'site/error',
        ]
Copy after login

is modified to:

'errorHandler' => [
            'errorAction' => 'error/error',
        ]
Copy after login

I am used to recreating an error The method depends on personal habits.

Create actionError in the error controller, as follows:

public function actionError(){
       $error = \Yii::$app->errorHandler->exception;
       $error_msg = '';
       if($error){
           $filed = $error->getFile();  //获取错误文件
           $line = $error->getLine();   //获取错误行数
           $message = $error->getMessage(); //获取错误消息
           $code = $error->getCode();   //获取错误码

           $log = new FileTarget();
           $log->logFile = \Yii::$app->getRuntimePath() . "/log/error.log"; //生成文件到log目录下

           $error_msg = $message ." [file:{$filed}][line:{$line}][message:{$message}][code:{$code}][url:{$_SERVER['REQUEST_URI']}][POST_DATA:".http_build_query($_POST)."]";

           $log->messages[] = [
               $error_msg,
               1,
               'applicition',
               microtime( true )
           ];
            $log->export();
       }
       return $error_msg;
   }
Copy after login

The error log will be generated in the runtime/log directory.

The above is the detailed content of How to manually generate error logs in Yii. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap

Video Face Swap

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

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)

How to open error log in php How to open error log in php Mar 09, 2021 pm 05:26 PM

How to open the error log in PHP: 1. Open the php.ini configuration file, find the "log_errors" option, and change the value of this option from "Off" to "On". 2. Use the ini_set() function to modify the PHP file, with the syntax "ini_set("log_errors", "On");".

Summary of frequently asked questions about importing Excel data into Mysql: How to deal with error log problems encountered when importing data? Summary of frequently asked questions about importing Excel data into Mysql: How to deal with error log problems encountered when importing data? Sep 10, 2023 pm 02:21 PM

Summary of frequently asked questions about importing Excel data into Mysql: How to deal with error log problems encountered when importing data? Importing Excel data into a MySQL database is a common task. However, during this process, we often encounter various errors and problems. One of them is the error log issue. When we try to import data, the system may generate an error log listing the specific information about the error that occurred. So, how should we deal with the error log when we encounter this situation? First, we need to know how

How to use PHP framework Yii to develop a highly available cloud backup system How to use PHP framework Yii to develop a highly available cloud backup system Jun 27, 2023 am 09:04 AM

With the continuous development of cloud computing technology, data backup has become something that every enterprise must do. In this context, it is particularly important to develop a highly available cloud backup system. The PHP framework Yii is a powerful framework that can help developers quickly build high-performance web applications. The following will introduce how to use the Yii framework to develop a highly available cloud backup system. Designing the database model In the Yii framework, the database model is a very important part. Because the data backup system requires a lot of tables and relationships

Error log query method to solve win10 crash problem Error log query method to solve win10 crash problem Jan 08, 2024 am 11:49 AM

If we encounter a crash when using the win10 system, we can query the error log after restarting the system normally to find out what caused the crash, and then we can prescribe the right medicine. So how to query the error log, let’s take a look below. How to check the error log of win10 crash: 1. First find this computer on the desktop, right-click it and select "Manage". 2. Then find "System Tools" under Computer Management and expand it. 3. Then find the "Event Viewer" and expand it again. 4. Then click "Windows Log" and select the event category you want to view on the right. 5. Click on a category and we can see what errors occurred when the computer crashed. 6. Click on one of the errors and you can

Symfony vs Yii2: Which framework is better for developing large-scale web applications? Symfony vs Yii2: Which framework is better for developing large-scale web applications? Jun 19, 2023 am 10:57 AM

As the demand for web applications continues to grow, developers have more and more choices in choosing development frameworks. Symfony and Yii2 are two popular PHP frameworks. They both have powerful functions and performance, but when faced with the need to develop large-scale web applications, which framework is more suitable? Next we will conduct a comparative analysis of Symphony and Yii2 to help you make a better choice. Basic Overview Symphony is an open source web application framework written in PHP and is built on

How to use Yii3 framework in php? How to use Yii3 framework in php? May 31, 2023 pm 10:42 PM

As the Internet continues to develop, the demand for web application development is also getting higher and higher. For developers, developing applications requires a stable, efficient, and powerful framework, which can improve development efficiency. Yii is a leading high-performance PHP framework that provides rich features and good performance. Yii3 is the next generation version of the Yii framework, which further optimizes performance and code quality based on Yii2. In this article, we will introduce how to use Yii3 framework to develop PHP applications.

Data query in Yii framework: access data efficiently Data query in Yii framework: access data efficiently Jun 21, 2023 am 11:22 AM

The Yii framework is an open source PHP Web application framework that provides numerous tools and components to simplify the process of Web application development, of which data query is one of the important components. In the Yii framework, we can use SQL-like syntax to access the database to query and manipulate data efficiently. The query builder of the Yii framework mainly includes the following types: ActiveRecord query, QueryBuilder query, command query and original SQL query

Yii2 vs Phalcon: Which framework is better for developing graphics rendering applications? Yii2 vs Phalcon: Which framework is better for developing graphics rendering applications? Jun 19, 2023 am 08:09 AM

In the current information age, big data, artificial intelligence, cloud computing and other technologies have become the focus of major enterprises. Among these technologies, graphics card rendering technology, as a high-performance graphics processing technology, has received more and more attention. Graphics card rendering technology is widely used in game development, film and television special effects, engineering modeling and other fields. For developers, choosing a framework that suits their projects is a very important decision. Among current languages, PHP is a very dynamic language. Some excellent PHP frameworks such as Yii2, Ph

See all articles