Skip to content

Commit

Permalink
Prepare for open source
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Apr 11, 2022
1 parent 1f4f183 commit 60b53c2
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 38 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
build
phpunit.xml
vendor
composer.lock
17 changes: 0 additions & 17 deletions .gitlab-ci.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .php_cs

This file was deleted.

32 changes: 32 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# Logstash formatter for Monolog v1 and v2


```yaml
# config/prod/monolog.yaml
monolog:
handlers:
filter_for_errors:
type: fingers_crossed
# if *one* log is error or higher, pass *all* to handler
action_level: warning
handler: cloudwatch
buffer_size: 100
excluded_http_codes: []

cloudwatch:
type: stream
path: 'php://stderr'
formatter: 'app.monolog.formatter.logstash'
level: info

services:
app.monolog.formatter.logstash:
class: Happyr\MonologLogstashFormatter\LogstashFormatter
arguments:
- 'app.example.com'

monolog.processor.uid:
class: Monolog\Processor\UidProcessor
autoconfigure: true
tags:
- { name: monolog.processor, handler: cloudwatch }
```
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rawls/monolog-logstash-formatter",
"name": "happyr/monolog-logstash-formatter",
"type": "library",
"description": "Monolog 1 Fogstash formatter",
"license": "proprietary",
Expand All @@ -17,6 +17,6 @@
"monolog/monolog": "^1.23 || ^2.0"
},
"autoload": {
"psr-4": { "Rawls\\Monolog\\Formatter\\": "src/" }
"psr-4": { "Happyr\\MonologLogstashFormatter\\": "src/" }
}
}
16 changes: 15 additions & 1 deletion src/LogstashFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rawls\Monolog\Formatter;
namespace Happyr\MonologLogstashFormatter;

use Monolog\Formatter\NormalizerFormatter;

Expand Down Expand Up @@ -87,10 +87,24 @@ public function format(array $record): string
$message[$this->contextKey] = $record['context'];
}

// TO support Funcitonbeat 8.x
if (isset($message[$this->contextKey]['message']) && is_array($message[$this->contextKey]['message'])) {
$message[$this->contextKey]['message'] = json_encode($message[$this->contextKey]['message']);
}

$json = $this->toJson($message);

// 8000 is the limit by PHP-FPM
if (\mb_strlen($json) > 8000 && isset($message['context']['exception']['previous'])) {
$message['context']['exception']['previous'] = ['removed' => 'Message too long'];
$json = $this->toJson($message);
}

// 8000 is the limit by PHP-FPM
if (\mb_strlen($json) > 8000 && isset($message['context']['exception'])) {
if ($message['context']['exception'] instanceof \Throwable) {
$message['context']['exception_class'] = get_class($message['context']['exception']);
}
unset($message['context']['exception']);
$json = $this->toJson($message);
}
Expand Down

0 comments on commit 60b53c2

Please sign in to comment.