Code Area PHP Tips and Tricks Tools and Technologies

Using CakePHP Logging Scope

Undoubtedly logging is most important part of an application to debugging, analyzing, measuring performance. So often times we want to handle different logging behavior for different components of our application. Assume that you are developing an e-commerce website and you want to handle logging cart & payment component differently.

So in that way, each log of the different component will store into a different file. So debugging will be easier than generic logging. To do that open config/bootstrap.php file and copy pastes this snippet.

Then you can implement this scope like this way (From controller & model).

Log::error('Product is not added into cart due to internal error', ['scope' => ['cart']]);
Log::emergency('Payment is not received', ['scope' => ['payments']]);


By Sohel Rana

PHP Programmer, Software Engineer & Technology lover

Leave a Reply

Your email address will not be published. Required fields are marked *