Skip to content

Commit

Permalink
Full status compatibility with datadog
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardK91 committed Apr 6, 2023
1 parent 182a838 commit 299a447
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Monolog Handler to forward logs to Datadog using async requests.

## Requirements
- PHP 8.0+
- PHP 8.1+
- PHP Curl

## Installation
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-curl": "*",
"monolog/monolog": "^3.0",
"guzzlehttp/guzzle": "^7.5"
Expand Down
35 changes: 0 additions & 35 deletions src/Monolog/Formatter/DatadogFormatter.php

This file was deleted.

13 changes: 8 additions & 5 deletions src/Monolog/Handler/DatadogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace sgoettsch\MonologDatadog\Handler;

use JsonException;
use Monolog\Formatter\JsonFormatter;
use Monolog\Handler\MissingExtensionException;
use Monolog\Level;
use Monolog\Logger;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Formatter\FormatterInterface;
use Monolog\LogRecord;
use sgoettsch\MonologDatadog\Formatter\DatadogFormatter;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

Expand Down Expand Up @@ -83,7 +83,12 @@ protected function send(LogRecord $record): void

$url = $this->host . '/api/v2/logs';

$payLoad = json_decode($record['formatted'], true, 512, JSON_THROW_ON_ERROR);
$formated = json_decode($record->formatted, true, 512, JSON_THROW_ON_ERROR);

// Datadog requires the log level in the status attribute.
$formated['status'] = strtolower($record['level_name']);

$payLoad = $formated;
$payLoad['ddsource'] = $source;
$payLoad['ddtags'] = $tags;
$payLoad['hostname'] = $hostname;
Expand Down Expand Up @@ -157,11 +162,9 @@ protected function getTags(LogRecord $record): string

/**
* Returns the default formatter to use with this handler
*
* @return DatadogFormatter
*/
protected function getDefaultFormatter(): FormatterInterface
{
return new DatadogFormatter();
return new JsonFormatter();
}
}

0 comments on commit 299a447

Please sign in to comment.