PHP code example of php-pico / logger

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

    

php-pico / logger example snippets


$level   = \Psr\Log\LogLevel::DEBUG;
$message = 'User {userId} signed in from {userIp}';
$context = [
    'userId' => 1,
    'userIp' => '127.0.0.1',
];

// Logs: "User 1 signed in from 127.0.0.1"
$logger->log($level, $message, $context);

use PhpPico\Logger\FileLogger;

$path     = __DIR__ . '/logs';
$file     = 'app.log';
$newLines = 2;

$logger = new FileLogger($path, $file, $newLines);

use PhpPico\Logger\StderrLogger;

$logger = new StderrLogger();

use PhpPico\Logger\TestLogger;

$logger = new TestLogger();

// Get logs stored
$logger->getLogs();

// Flush the logs (down the toilet)
$logger->flush();