/monolog-datadog

Forward logs to datadog

Primary LanguagePHPMIT LicenseMIT

Datadog Monolog integration

Monolog Handler to forward logs to Datadog using async requests.

Requirements

  • PHP 8.0+
  • PHP Curl

Installation

composer require xtain/monolog-datadog

Basic Usage

<?php

use Monolog\Logger;
use XTAIN\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, 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');