PHP code example of ch17 / blue-log

1. Go to this page and download the library: Download ch17/blue-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/ */

    

ch17 / blue-log example snippets


    // Setup default log Channel
    'default_log_channel' => 'Default',

    // Setup default log Level
    // info, debug, error, warning
    'default_log_level' => 'debug',

    // False if authenticated user information should not be stored
    'store_logged_by' => true,

    // add fields want to store for login user as created_by
    'logged_by_fields' => [
        'id',
        'email',
    ],

use Ch17\BlueLog\Facades\BlueLog as Log;

   Log::debug('default', 'This is a debug message', ['context' => 'value'], ['extra' => 'value']);
   Log::info('default', 'This is an info message', ['context' => 'value'], ['extra' => 'value']);
   Log::warning('default', 'This is a warning message', ['context' => 'value'], ['extra' => 'value']);
   Log::error('default', 'This is an error message', ['context' => 'value'], ['extra' => 'value']);

use Ch17\BlueLog\Facades\BlueLog as Log;

   Log::error([
    'message' => 'a new error message'
   ]);

    Log::warning([
      'channel' => 'user.create',
      'message' => 'a new warning message'
   ]);

use Ch17\BlueLog\Services\BlueLogger as logger;

   protected $logger;

    public function __construct(BlueLogger $logger)
    {
        $this->logger = $logger;
    }

use Ch17\BlueLog\Services\BlueLogger as logger;

   $logger = new BlueLogger();

$this->logger->debug('default', 'This is a debug message', ['context' => 'value'], ['extra' => 'value']);
$this->logger->info('default', 'This is an info message', ['context' => 'value'], ['extra' => 'value']);
$this->logger->warning('default', 'This is a warning message', ['context' => 'value'], ['extra' => 'value']);
$logger->info('USER-DELETE', 'User deleted successfully!', ['deletedUser' => json_encode([])], ['extra' => 'value']);

    $logger->error([
    'message' => 'a new error message'
   ]);

    $logger->warning([
      'channel' => 'user.create',
      'message' => 'a new warning message',
      'context' => ['deletedUser' => json_encode($createdUser)]
   ]);
bash
   php artisan vendor:publish --tag=blue-log-migrations
   php artisan vendor:publish --tag=blue-log-config
   
bash
   php artisan migrate