PHP code example of sgoettsch / monolog-datadog
1. Go to this page and download the library: Download sgoettsch/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/ */
sgoettsch / monolog-datadog example snippets
use Monolog\Logger;
use sgoettsch\MonologDatadog\Handler\DatadogHandler;
$apiKey = 'DATADOG-API-KEY';
$host = 'https://http-intake.logs.datadoghq.com'; // could be set to other domains for example for EU hosted accounts ( https://http-intake.logs.datadoghq.eu )
$attributes = [
'hostname' => 'YOUR_HOSTNAME',
'source' => 'php',
'service' => 'YOUR-SERVICE'
];
$logger = new Logger('datadog-channel');
$datadogLogs = new DatadogHandler($apiKey, $host, $attributes, Monolog\Level::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');