PHP code example of pagon / logger

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

    

pagon / logger example snippets


$logger = new \Pagon\Logger();
$logger->debug('User->%s is logged with params: %s', $username, $params);
// 2013-05-02 13:11:00 - s3f9da -   debug  - User->hfcorriez is logged with params: return=/status
$logger->info('User->:username login to homepage', array(':username' => $username))
// 2013-05-02 13:11:00 - s3f9da -   info   - User->hfcorriez login to homepage

$logger = new \Pagon\Logger(array(
    'level' => 'info',
    'file'  => '/tmp/app.log'
));

$logger = new \Pagon\Logger(array(
	'format' => '$time - $level - $text'
));

$logger = new \Pagon\Logger(array(
	'format' => '$time - $level - $file - $text'
));
$logger->file = __FILE__;
$logger->info('Some info');	// 2013-05-02 13:11:00 - info - /home/hfcorriez/myfile.php - Some info

$logger = new \Pagon\Logger();
$logger->add('debug', new \Pagon\Logger\Console());

class YourCustomHanlder extends \Pagon\LoggerInterface
{
    public function write()
    {
        if (empty($this->messages)) return;

        $message = join("\n", $this->buildAll()) . "\n";
        
        mail('[email protected]', 'Some error logs', $message);
    }
}

$logger = new \Pagon\Logger();
$logger->add('error', new YourCustomHanlder());

$logger = new \Pagon\Logger();
$logger->on('flush', function() {
    // Some thing before the flush
});