xtain/monolog-datadog

Monolog Handler to forward logs to Datadog using async requests.

1.0.4 2022-11-17 13:29 UTC

This package is auto-updated.

Last update: 2024-10-17 18:08:38 UTC


README

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');