Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

guspio/monolog-datadog

Repository files navigation

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