quarkiverse / quarkus-logging-json

Quarkus logging extension outputting the logging in json.
Apache License 2.0
62 stars 28 forks source link

Malformed JSON with duplicated structured arguments #276

Open langsamu opened 10 months ago

langsamu commented 10 months ago

Many thanks for the great work.

Summary

Using 3.0.0, malformed JSON log output can be trivially produced by including structured arguments with names equal to those emitted by the library itself.

Repro

https://github.com/langsamu/quarkiverse-json-duplicate-structured-argument.

Example

Log.infov("Something from resource", kv("timestamp", "timestamp from resource");

results in log output with two properties named timestamp because that property is also added by TimestampJsonProvider.

Possible mitigation

I have several ideas about possible improvements:

  1. The ArgumentsJsonProvider could be made aware of the (configurable) field names used by the other providers so it can
    1. throw on duplication,
    2. ignore on duplication or
    3. override on duplication: User supplied structured arguments could take precedence over those generated by the library itself. This would not play nice with streaming behavior and would require a substantial change.
  2. A configuration setting could be added to instruct the arguments provider what to do in case of duplication.
  3. A note could be added to the README,
    1. perhaps reminding callers that they can collect custom args under quarkus.log.json.fields.arguments.field-name.