PHP code example of helissonms / monolog-datadog

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

    

helissonms / monolog-datadog example snippets




use Monolog\Logger;
use MonologDatadog\Handler\DatadogHandler;

// Add your [Datadog Api Key]
$apiKey = 'YOUR-DATADOG-API-KEY';

$attributes = [
    'hostname' => 'YOUR_HOSTNAME', // Default: $_SERVER['SERVER_NAME']
    'source' => 'php', // Default: php
    'service' => 'YOUR-SERVICE' // Default: Monolog channel name
];

$logger = new Logger('datadog-channel');

$datadogLogs = new DatadogHandler($apiKey, $attributes, Logger::INFO);

$logger->pushHandler($datadogLogs);

$logger->info('i am an info');
$logger->warning('i am a warning..');
$logger->error('i am an error ');
$logger->notice('i am a notice');
$logger->emergency('i am an emergency');