PHP code example of anekdotes / logger

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

    

anekdotes / logger example snippets


    use Anekdotes\Logger\Log;
    Log::info(["message" => "toaster","user_identification" => "4N3K"]);

    use Anekdotes\Logger\Log;
    use Anekdotes\Logger\Drivers\FileDriver;
    //Set Driver and use it
    Log::setDriver(new FileDriver('logname','tmp/logs/toaster.log'));
    Log::info(["message" => "toaster","user_identification" => "4N3K"]);

    use Anekdotes\Logger\Log;
    use Anekdotes\Logger\Drivers\FileDriver;
    //Set Driver and use it
    Log::setDriver(new ConsoleDriver()); 
    Log::info(["message" => "toaster","user_identification" => "4N3K"]);

    $data = ["data" => "data"];
    $functionThatLogsIntoDatabase = function () use ($data) { 
      //Log $data in the database 
    };
    Log::setErrorHandler($functionThatLogsIntoDatabase);
    Log::error($data);

    $data = ["data" => "data"];
    $functionThatLogsIntoDatabase = function ($LogData) {
      //Log $LogData in the DB. Note the LogData is the exact output that will be saved to a file. It is in JSON Format. 
    };
    Log::setCriticalHandler($functionThatLogsIntoDatabase);
    Log::critical($data);

    Log::info([]);
    Log::success([]);
    Log::warn([]);
    Log::error([]);
    Log::critical([]);