PHP code example of apix / log

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

    

apix / log example snippets



$urgent_logger = new Apix\Log\Logger\Mail('[email protected]');
$urgent_logger->setMinLevel('critical');   // catch logs >= to `critical`

$urgent_logger->alert('Running out of {stuff}', ['stuff' => 'beers']);

$app_logger = new Apix\Log\Logger\File('/var/log/apix_app.log');
$app_logger->setMinLevel('warning')  // intercept logs that are >= `warning`
           ->setCascading(false)     // don't propagate to further buckets
           ->setDeferred(true);      // postpone/accumulate logs processing

// The main logger object (injecting an array of loggers)
$logger = new Apix\Log\Logger( array($urgent_logger, $app_logger) );

if(DEBUG) {
  // Bucket for the remaining logs -- i.e. `notice`, `info` and `debug`
  $dev_logger = new Apix\Log\Logger\Stream(); // default to screen without output buffer
  // $dev_logger = new Logger\File('/tmp/apix_debug.log'); 
  $dev_logger->setMinLevel('debug');

  $logger->add($dev_logger);   		// another way to inject a log bucket
}

$e = new \Exception('Boo!');

// handled by both $urgent_logger & $app_logger
$logger->critical('OMG saw {bad-exception}', [ 'bad-exception' => $e ]);

// handled by $app_logger
$logger->error($e); // push an object (or array) directly

// handled by $dev_logger
$logger->info('Testing a var {my_var}', array('my_var' => array(...)));