Skip to content

Commit

Permalink
Allow set Logdna tags on handler @slepic
Browse files Browse the repository at this point in the history
  • Loading branch information
slepic authored and nvanheuverzwijn committed Feb 2, 2024
1 parent 91e05f0 commit a70c11e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Monolog/Handler/LogdnaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class LogdnaHandler extends \Monolog\Handler\AbstractProcessingHandler {
*/
private $mac = '';

/**
* @var string $tags
*/
private $tags = '';

/**
* @var resource $curl_handle
*/
Expand All @@ -60,6 +65,13 @@ public function setMAC($value) {
$this->mac = $value;
}

/**
* @param string $tags
*/
public function setTags($tags) {
$this->tags = $tags;
}

/**
* @param string $ingestion_key
* @param string $hostname
Expand All @@ -85,7 +97,14 @@ protected function write(array $record): void {
$headers = ['Content-Type: application/json'];
$data = $record["formatted"];

$url = \sprintf("https://logs.logdna.com/logs/ingest?hostname=%s&mac=%s&ip=%s&now=%s", $this->hostname, $this->mac, $this->ip, $record['datetime']->getTimestamp());
$query = [
'hostname' => $this->hostname,
'now' => $record['datetime']->getTimestamp(),
'mac' => $this->mac,
'ip' => $this->ip,
'tags' => $this->tags
];
$url = 'https://logs.logdna.com/logs/ingest?' . \http_build_query(\array_filter($query));

\curl_setopt($this->curl_handle, CURLOPT_URL, $url);
\curl_setopt($this->curl_handle, CURLOPT_USERPWD, "$this->ingestion_key:");
Expand Down

0 comments on commit a70c11e

Please sign in to comment.