PHP code example of cakephp / log

1. Go to this page and download the library: Download cakephp/log library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cakephp / log example snippets


use Cake\Cache\Cache;

use Cake\Log\Log;

// Short classname
Log::config('local', [
    'className' => 'FileLog',
    'levels' => ['notice', 'info', 'debug'],
    'file' => '/path/to/file.log',
]);

// Fully namespaced name.
Log::config('production', [
    'className' => \Cake\Log\Engine\SyslogLog::class,
    'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
]);

Log::config('special', function () {
	// Return any PSR-3 compatible logger
	return new MyPSR3CompatibleLogger();
});

Log::config('special', new MyPSR3CompatibleLogger());

Log::write('debug', 'Something did not work');

// Configure /logs/payments.log to receive all levels, but only
// those with `payments` scope.
Log::config('payments', [
    'className' => 'FileLog',
    'levels' => ['error', 'info', 'warning'],
    'scopes' => ['payments'],
    'file' => '/logs/payments.log',
]);

Log::warning('this gets written only to payments.log', ['scope' => ['payments']]);