Console Logger plugin for CakePHP
Logs whatever you want to console., (*1)
Usage:, (*2)
Import Logger, (*3)
use ConsoleLogger\Log\Logger;
And then:, (*4)
Logger::log('message', 'info');
log function can receive as a message an array, object or string.
Second parameter is level, used mostly for styling., (*5)
There are some pre defined levels:, (*6)
$output->styles('annoy', ['text' => 'yellow', 'blink' => true]);
$output->styles('http_response', ['text' => 'yellow']);
$output->styles('http_request', ['text' => 'cyan']);
And some defined in Cake's class ConsoleOutput:, (*7)
protected static $_styles = [
'emergency' => ['text' => 'red'],
'alert' => ['text' => 'red'],
'critical' => ['text' => 'red'],
'error' => ['text' => 'red'],
'warning' => ['text' => 'yellow'],
'info' => ['text' => 'cyan'],
'debug' => ['text' => 'yellow'],
'success' => ['text' => 'green'],
'comment' => ['text' => 'blue'],
'question' => ['text' => 'magenta'],
'notice' => ['text' => 'cyan']
];
There is one base controller that could be used to log every action.
In your AppController:, (*8)
...
use ConsoleLogger\Controller\BaseController;
class AppController extends BaseController
{
...
There is also a wrapper for Http Client class that logs every http method requests and responses
Instead of using Cake's Http Client do:, (*9)
use ConsoleLogger\Http\Client;
A behavior is also included in oder to log every query that is executed in the BeforeFind callback.
In order to use it just add the following line to the desired Table:, (*10)
$this->addBehavior('ConsoleLogger.Log')
Installation
You can install this plugin into your CakePHP application using composer., (*11)
The recommended way to install composer packages is:, (*12)
composer require fabcam/console-logger