Skip to content

Commit 827d112

Browse files
juanparatiJuan Lago
authored and
Juan Lago
committed
Smart serialization will not serialize empty or null values.
1 parent c208350 commit 827d112

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Diff for: README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Laralog can send logs to different services like ElasticSearch and Datadog.
7676
|--to-timezone=[zone]|Convert logs to a different timezone See [timezone list](http://php.net/manual/en/timezones.php) (Only ElasticSearch).|
7777
|--sender=[sender]|Sender to use: elasticsearch (Default) or datadog.|
7878
|--hostname=[hostname]|Override the default hostname.|
79+
|--smart|Serialize JSON context when is possible.|
7980
|-v|Verbose mode that output the new log entries to STDOUT.|
8081

8182

@@ -130,7 +131,17 @@ Benefits of the safe file handler:
130131
The safe file handler do not use LibEvent, inotify or another file event notification mechanism so instead it uses a regular file check (See "--read-freq=[ms]" parameter). This makes the log file check process a bit slow but in this way the LibEvent extension is not required.
131132

132133

133-
## 9. How to build Laralog
134+
## 9. Smart serialization
135+
136+
The option "--smart" will automatically serialize the JSON chunks found in the context and send it as the "parameters" field.
137+
138+
Example:
139+
140+
[2019-11-24 06:30:56] production.INFO: Job finished {"connection":"database","queue":"default","job":"SendNewsletter"}
141+
142+
The previous log entry contains JSON chunk as context and normally it's send to the Logstash or Datadog as a string, however with the smart serialization option Laralog will try to extract the JSON part and send it as the field "params".
143+
144+
## 10. How to build Laralog
134145

135146
Laralog is available as a self-executable PHAR file, however if you want to build your own custom PHAR you need to follow the following steps:
136147

@@ -141,7 +152,7 @@ Laralog is available as a self-executable PHAR file, however if you want to buil
141152
caveman build . -x -r
142153

143154

144-
## 10. Download
155+
## 11. Download
145156

146157
If you are lazy and you don't want to build your Laralog version, you are welcome to download the following executable (PHAR file):
147158

Diff for: src/App/Model/LogParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static function parseLogEntry(
101101
/**
102102
* Deserialize data and add it to params.
103103
*/
104-
if ($smart_serialization)
104+
if (!empty(trim($log['data'])) && $smart_serialization)
105105
{
106106
$params = json_decode($data, true);
107107

Diff for: src/Config/Version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
return array (
33
'major' => 2,
44
'minor' => 7,
5-
'build' => 49,
5+
'build' => 51,
66
'codename' => '',
77
);

0 commit comments

Comments
 (0)