<div dir="ltr">> log {<br>>   source { example-msg-generator(num(1) template("{\"category\":\"BOOT\",\"level\":\"INFO\",\"message\":\"Check pstore partition..\"}")); };<br>>   parser { json-parser(); };<br>>   destination { file(/dev/stdout template("$(format-json --key category,level,message timestamp=${ISODATE})\n")); };<br>>};<br><br>Ok so first I update the syslog-ng config file with your modification<br><br>diff --git a/board/xxx/xxx/rootfs/etc/syslog-ng.conf b/board/xxx/xxx/rootfs/etc/syslog-ng.conf<br>index c28ea5e59d..6b93ce24b8 100644<br>--- a/board/xxx/xxx/rootfs/etc/syslog-ng.conf<br>+++ b/board/xxxx/xxx/rootfs/etc/syslog-ng.conf<br>@@ -4,10 +4,6 @@ filter f_middleware {<br>     facility("local1");<br> };<br>-template t_json_filetemplate {<br>-    template("{\"timestamp\":\"${ISODATE}\",${MESSAGE}\n");<br>-};<br> source s_kernel {<br>        file("/proc/kmsg" program_override("kernel"));<br> };<br>@@ -21,7 +17,8 @@ destination d_kernel {<br> };<br> destination d_middleware {<br>-       file("/data/logs/middleware.log", template(t_json_filetemplate));<br>+       file(/data/logs/middleware.log template("$(format-json --key category,level,message timestamp=${ISODATE})\n"));;<br>+      <br> };<br> log {<br>@@ -31,6 +28,7 @@ log {<br> <br> log {<br>        source(s_middleware);<br>+       parser { json-parser(); };<br>        filter(f_middleware);<br>        destination(d_middleware);<br> };<br><br>I also add the '{' in my macro log<br><br>diff --git a/log/log_private.h b/log/log_private.h<br>index b1e2dd31..09e875e1 100644<br>--- a/log/log_private.h<br>+++ b/log/log_private.h<br>@@ -18,7 +18,7 @@<br> #define _PRINT_DEBUG(M, ...)                                                   \<br>        do {                                                                    \<br>-               syslog(LOG_DEBUG, "\"category\":\"%s\",\"level\":\"DEBUG\",\"message\":\"" M "%s\"}\n", __DIR__, __VA_ARGS__); \<br>+               syslog(LOG_DEBUG, "{\"category\":\"%s\",\"level\":\"DEBUG\",\"message\":\"" M "%s\"}\n", __DIR__, __VA_ARGS__); \<br>        } while (0)<br> #else<br>@@ -28,32 +28,32 @@<br> #define _PRINT_INF_GOTO(M, ...)                                                                \<br>        do {                                                                                    \<br>-               syslog(LOG_DEBUG, "\"category\":\"%s\",\"level\":\"INFO\",\"message\":\"" M "%s\"}\n", __DIR__, __VA_ARGS__); \<br>+               syslog(LOG_DEBUG, "{\"category\":\"%s\",\"level\":\"INFO\",\"message\":\"" M "%s\"}\n", __DIR__, __VA_ARGS__); \<br>                errno = 0;                                                                      \<br>                goto error;                                                                     \<br>(...)<br> #endif /* !LOG_PRIVATE_H_ */<br><br>So basically I suppose that your modification allows to syslog-ng  to understand by itself that there is an extra pair key/value<br>in my format and that I am using JSON format.  So let's do some test now...<br><br>int main (void)<br>{<br>  PRINT_DEBUG ("Test simple.");<br>  PRINT_DEBUG ("\nTest with return line\n.");<br>  PRINT_DEBUG ("Test with json inside message : {\"key\" : \"%d\", \"key2\" : \"%d\"} ", 42, 21);<br>  PRINT_DEBUG ("Test simple2.");<br>  PRINT_DEBUG ("Begin. Program name : %s", argv[0]);<br> (...)<br>}<br><br>Result :<br><br># cat /data/logs/middleware.log<br>{"timestamp":"2020-04-24T15:36:28+02:00","message":"Test simple.","level":"DEBUG","category":"MPU_CORE"}<br>{"timestamp":"2020-04-24T15:36:28+02:00","message":"Test simple2.","level":"DEBUG","category":"MPU_CORE"}<br>{"timestamp":"2020-04-24T15:36:28+02:00","message":"Begin. Program name : nano_core","level":"DEBUG","category":"MPU_CORE"}<br>{"timestamp":"2020-04-24T15:36:28+02:00","message":"Board config : nano_proto1","level":"DEBUG","category":"MPU_CORE"}<br>{"timestamp":"2020-04-24T15:36:28+02:00","message":"Initialize GPIO..","level":"INFO","category":"GPIO_MANAGER"}<br>{"timestamp":"2020-04-24T15:36:28+02:00","message":"Synchronize dictionnary with current rootfs content","level":"INFO","category":"AUDIO_MANAGER"}<br><br>As you can see, the line with \n and the JSON debug output is not in the final log. It was not in a good format for the JSON syslog-ng parser.<br>How can I fix that? Now that syslog-ng is able to understand that there is a category, a level, a message in my JSON. I cannot just ask for <br>syslog-ng to use the escape template only on the column with message key before sending the message to the parser?<br><br>I am able to fix the \n issue by using unix-dgram instead of unix-stream but without really understand why. New result after using unix-dgram :<div><br></div><div>{"timestamp":"2020-04-24T15:58:09+02:00","message":"Test simple.","level":"DEBUG","category":"MPU_CORE"}<br>{"timestamp":"2020-04-24T15:58:09+02:00","message":"\nTest with return line\n.","level":"DEBUG","category":"MPU_CORE"}<br>{"timestamp":"2020-04-24T15:58:09+02:00","message":"Test simple2.","level":"DEBUG","category":"MPU_CORE"}<br>{"timestamp":"2020-04-24T15:58:09+02:00","message":"Begin. Program name : nano_core","level":"DEBUG","category":"MPU_CORE"}<br><br></div></div>