PHP code example of phpdevcommunity / psr3-logger

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

    

phpdevcommunity / psr3-logger example snippets




use PhpDevCommunity\Log\Handler\FileHandler;
use PhpDevCommunity\Log\Logger;
use Psr\Log\LogLevel;

// Define the log file path
$logFileName = dirname(__DIR__) . '/var/log/' . date('Y-m-d') . '.log';

// Create a file handler for logging to a file
$handler = new FileHandler($logFileName);

// Initialize the logger with the file handler
$logger = new Logger($handler);

// Log an emergency message
$logger->log(LogLevel::EMERGENCY, 'An error has occurred');