Logging and using the context information
Sometimes a log message is not enough to fix an error. For example, if you are following best practices and developing and testing an application with all possible errors reported, you can get an error message. However, without the execution context, it is only telling you that there was an error and it is not clear what actually caused it.
For our example, we will use a very simple and poorly coded action that just echoes Hello, <username>!
where the username
is taken directly from $_GET
.
Getting ready
Create a new yii2-app-basic
application by using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guidestart-installation.html.
How to do it...
Carry out the following steps:
- First, we will need a controller to work with. Therefore, create
protected/controllers/LogController.php
as follows:<?php namespace app\controllers; use yii\web\Controller; class LogController extends Controller { ...