PHP code example of ddniel16 / php-logger

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

    

ddniel16 / php-logger example snippets


$logs->alert($message, $context);
$logs->critical($message, $context);
$logs->custom($message, $context);
$logs->debug($message, $context);
$logs->emergency($message, $context);
$logs->error($message, $context);
$logs->info($message, $context);
$logs->log(0, $message, $context);
$logs->notice($message, $context);
$logs->success($message, $context);
$logs->warning($message, $context);



$logs = new \PhpLogger\PhpLogger();
$logs->setOutput(true);

$message = 'Hello Mr. {name} {lastname} Matrix awaits you!';
$context = array('name' => 'Jack', 'lastname' => 'Sparrow');

$logs->debug($message, $context);




$syslog = new \PhpLogger\Syslog('testting');

$logger = new \PhpLogger\PhpLogger();
$logger->setSyslog($syslog);

$logger->debug('--> syslog <--');




$optionsFile = array(
    'logDir' => __DIR__ . '/logs',
    'name' => 'php-logger',
    'ext' => 'log',
    'dateFormat' => 'd-m-Y H:i:s P',
    'maxLogs' => 3,
    'maxSize' => 700
);

$file = new \PhpLogger\File($logFile);

$logger = new \PhpLogger\PhpLogger();
$logger->setFile($file);

$logger->debug('debug message');


class CustomLogger implements PhpLogger\CustomInterface
{

    public function writeLog(
        $message,
        $priority = LOG_DEBUG,
        $priorityMsg = '[debug]'
    )
    {

        if ($priority === LOG_CRIT) {
            mail('[email protected]', $priorityMsg, $message);
        }

    }

}

$logs = new \PhpLogger\PhpLogger();
$logs->setCustom(new CustomLogger());
$logs->setOutput(false);

$message = 'Hola Sr. {name} {lastname}';
$context = array('name' => 'Jack', 'lastname' => 'Sparrow');

$logs->critical($message, $context);