PHP code example of maplephp / log

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

    

maplephp / log example snippets


use MaplePHP\Log\Logger;
use MaplePHP\Log\Handlers\StreamHandler;

$log = new Logger(new StreamHandler("/path/to/logger.log"));
$log->warning("The user {firstname} has been added.", ["firstname" => "John", "lastname" => "Doe"]);

$log = new Logger(new StreamHandler("/path/to/logger.log", StreamHandler::MAX_SIZE, StreamHandler::MAX_COUNT));
$log->warning("The user {firstname} has been added.", ["firstname" => "John", "lastname" => "Doe"]);

use MaplePHP\Log\Logger;
use MaplePHP\Log\Handlers\DBHandler;

$dbHandler = new DBHandler();
$error = $dbHandler->create();
if (count($error) > 0) {
    echo "<pre>";
    print_r($error);
    echo "</pre>";
} else {
    echo "<p>The Logger database table has been installed!</p>";
}

$log = new Logger(new DBHandler());
$log->warning("The user {firstname} has been added.", ["user_id" => 4, "firstname" => "Daniel"]);

use MaplePHP\Log\Logger;
use MaplePHP\Log\Handlers\ErrorLogHandler;

$log = new Logger(new ErrorLogHandler("/path/to/logger.log"));
$log->warning("The user {firstname} has been added.", ["firstname" => "John", "lastname" => "Doe", "data" => ["city" => "Stockholm", "coor" => "122,1212"]]);