-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send logdna now argument in milliseconds #23
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,11 @@ class LogdnaHandler extends \Monolog\Handler\AbstractProcessingHandler | |
*/ | ||
private $tags = ''; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $include_request_time = true; | ||
|
||
/** | ||
* @var resource $curl_handle | ||
*/ | ||
|
@@ -75,6 +80,11 @@ public function setTags($tags) | |
$this->tags = $tags; | ||
} | ||
|
||
public function setIncludeRequestTime($include) | ||
{ | ||
$this->include_request_time = $include; | ||
} | ||
|
||
/** | ||
* @param string $ingestion_key | ||
* @param string $hostname | ||
|
@@ -108,6 +118,11 @@ protected function write(\Monolog\LogRecord $record): void | |
'ip' => $this->ip, | ||
'tags' => $this->tags | ||
]; | ||
|
||
if ($this->include_request_time) { | ||
$query['now'] = $this->getCurrentTimeInMilliseconds(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could replace this with just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
$url = 'https://logs.mezmo.com/logs/ingest?' . \http_build_query(\array_filter($query)); | ||
|
||
\curl_setopt($this->curl_handle, CURLOPT_URL, $url); | ||
|
@@ -128,4 +143,11 @@ protected function getDefaultFormatter(): FormatterInterface | |
{ | ||
return new \Zwijn\Monolog\Formatter\LogdnaFormatter(); | ||
} | ||
|
||
private function getCurrentTimeInMilliseconds(): string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just remove this function or replace it's content with
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
$time = \microtime(); | ||
$parts = \explode(' ', $time, 2); | ||
return $parts[1] . \str_pad((string) \round(1000.0 * (float) $parts[0]), 3, '0', \STR_PAD_LEFT); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing @param documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added