PHP code example of 8ctopus / apix-log

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

    

8ctopus / apix-log example snippets


$console = (new Apix\Log\Logger\Stream('php://stdout'))
   ->setMinLevel('debug')
   ->setFormat(new Apix\Log\Format\ConsoleColors())
   ->notice('Running out of {items}', 'Running out of {items} - left {left}', [
      'items' => 'beers',
      'left' => 5,
   ]);

$file = (new Apix\Log\Logger\File(__DIR__ . '/app.log'))
   // intercept logs that are >= `warning`
   ->setMinLevel('warning')
   // propagate to other loggers
   ->setCascading(true)
   // postpone writing logs to file
   ->setDeferred(true)
   // flush logs to file once 100 logs are collected
   ->setDeferredTrigger(100);

$logger = new Apix\Log\Logger([$console, $file]);

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

// handled by all loggers
$logger->critical('OMG saw {bad-exception}', ['bad-exception' => $exception]);

// push an object (or array) directly
$logger->error($exception);

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