PHP code example of mmdm / sim-logger

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

    

mmdm / sim-logger example snippets

 
composer 



// to instance a logger object
$logger = new Logger(new FileHandler($directory_to_store_logs));

// now use logger functions, for instance debug method
$logger->debug('this is a debug message');

$logger = new Logger([$handler[, $format[, $date_format]]]);

class CustomHandler implements IHandler
{
    /**
     * CunstomHandler constructor.
     */
    public function __construct()
    {
        // do initialize your needed things
    }

    /**
     * @return IHandler
     */
    public function init(): IHandler
    {
        // to whatever need for handler initialization
        
        return $this;
    }

    /**
     * @param string $message
     * @param array $data
     * @return bool
     */
    public function write(string $message, array $data = []): bool
    {
        // write $message with your log handler
        // $data have all parameters as key => value pairs
        
        // return true if write was OK or false if it wasn't
    }
}

// log emergency
$logger->emergency($message);

// log alert
$logger->alert($message);

// log critical
$logger->critical($message);

// log error
$logger->error($message);

// log warning
$logger->warning($message);

// log notice
$logger->notice($message);

// log info
$logger->info($message);

// log debug
$logger->debug($message);

// or you can use log function to log any level you want,
// including previous functions
$logger->log($message, LOGGER::DEBUG);
// or
$logger->log($message, 'custom level');

$logger->extraParameters([
'other_parameter' => $valueOfParameter
])->format('{level} - {other_parameter} - {message}');

// now we can use log methods
$logger->log('a log message', 'custom level');

$logger->dateFormat('Y/m/d H:i');

$logger->setTimezone('America/New_York');