PHP code example of stackify / monolog

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

    

stackify / monolog example snippets


use Monolog\Logger;
use Stackify\Log\Monolog\Handler as StackifyHandler;

$handler = new StackifyHandler('application_name', 'environment_name');
$logger = new Logger('logger');
$logger->pushHandler($handler);

$handler = new StackifyHandler('application_name', 'environment_name', null, true); 

use Stackify\Log\Transport\ExecTransport;
use Stackify\Log\Monolog\Handler as StackifyHandler;

$transport = new ExecTransport('api_key');
$handler = new StackifyHandler('application_name', 'environment_name', $transport);
$logger = new Logger('logger');
$logger->pushHandler($handler);

$transport = new ExecTransport($apiKey, ['proxy' => 'https://55.88.22.11:3128']);

$transport = new ExecTransport($apiKey, ['curlPath' => '/usr/bin/curl']);

$handler = new StackifyHandler('application_name', 'environment_name', $transport, true); 

try {
    $db->connect();
catch (DbException $ex) {
    // you may use any key name
    $logger->addError('DB is not available', ['ex' => $ex]);
}

use Monolog\Logger;
use Stackify\Log\Monolog\Handler as StackifyHandler;

$config = array(
        'CaptureServerVariables' => false,
        'CaptureServerVariablesWhitelist' => '*',
        'CaptureServerVariablesBlacklist' => 'REMOTE_ADDR,SERVER_ADDR',
        ...
    );

$transport = new ExecTransport($apiKey, [
    'config' => $config
]);

$handler = new StackifyHandler('application_name', 'environment_name', $transport);
$logger = new Logger('logger');
$logger->pushHandler($handler);

use Monolog\Logger;
use Stackify\Log\Monolog\Handler as StackifyHandler;

$transport = new ExecTransport($apiKey); // Your selected transport (Can be null which defaults to AgentSocketTransport)
$logServerVariables = false; // Default
$config = array(
        'CaptureServerVariables' => false,
        'CaptureServerVariablesWhitelist' => '*',
        'CaptureServerVariablesBlacklist' => 'REMOTE_ADDR,SERVER_ADDR',
        ...
);

$handler = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config);
$logger = new Logger('logger');
$logger->pushHandler($handler);

use Monolog\Logger;
use Stackify\Log\Monolog\Handler as StackifyHandler;

$transport = new ExecTransport($apiKey); // Your selected transport (Can be null which defaults to AgentSocketTransport)
$logServerVariables = false; // Default
$config = array(
        'IncludeChannel' => true,
        ...
);

$handler = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config);
$logger = new Logger('logger');
$logger->pushHandler($handler);

use Monolog\Logger;
use Stackify\Log\Monolog\Handler as StackifyHandler;

$transport = new ExecTransport($apiKey); // Your selected transport (Can be null which defaults to AgentSocketTransport)
$logServerVariables = false; // Default
$config = array(
        'IncludeExtraInContext' => true,
        ...
);

$handler = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config);
$logger = new Logger('logger');
$logger->pushProcessor(function ($record) {
      if (empty($record['extra'])) {
        $record['extra'] = [];
      }
      $record['extra']['dummy'] = 1;
      return $record;
});
$logger->pushHandler($handler);

$transport = new ExecTransport($apiKey, ['debug' => true]);

$config = array(
        'DebugLogPath' => '/path/to/log.log',
        'Debug' => true
    );

$logger = new StackifyHandler('application_name', 'environment_name', $transport, $logServerVariables, $config);