thestalnakergroup/monolog-datadog

Monolog Handler for Datadog Logs

dev-master 2023-07-03 14:04 UTC

This package is not auto-updated.

Last update: 2024-04-22 17:52:57 UTC


README

Build Status Latest Stable Version PHP from Packagist Licence

Datadog Monolog integration

MonologDatadog is a Datadog Log handler for Monolog. It enables you to send logs directly to HTTP with Curl.

Requirements

Features

  • Send Monolog logs directly to HTTP with Curl
  • Automatically JSON Formatted

Installation

Install the latest version with

composer require guspio/monolog-datadog

Basic Usage

<?php

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