zio / zio-logging

Powerful logging for ZIO 2.0 applications, with compatibility with many logging backends out-of-the-box.
https://zio.dev/zio-logging/
Apache License 2.0
175 stars 82 forks source link

Empty spans rendered as invalid json #783

Closed gavares closed 1 year ago

gavares commented 1 year ago

zio-logging version: 2.1.14

Used with:

Log configuration is read from HOCON with format string:

logger.formatformat =     "%label{timestamp}{%timestamp} %label{level}{%level} %label{fiberId}{%fiberId} %label{message}{%message} %label{cause}{%cause} %label{loggerName}{%name} %label{spans}{%spans} %kvs"

Any calls to log methods in scopes which do not have defined spans result in invalid json. For example, a logDebug message printed from a webserver filter:

logDebug("a log message")

Results in:

{
  "timestamp":"2023-11-04T13:47:10.732971635Z",
  "level":"DEBUG",
  "fiberId":"zio-fiber-409138",
  "message":"a log message",
  "loggerName":"sttp.tapir.server.ziohttp.ZioHttpServerOptions",
  "spans":
}

newlines added for readability

You can see in the last line that logging with no defined spans prints a key, there is a call to LogAppender.closeKeyOpenValue() and then nothing is printed.

The right behavior here is likely one of:

justcoon commented 1 year ago

@gavares thank you very much for report, look like there is general issue in case where json attribute value is empty, and does not matter if it is span or something else,

I created fix for that #784

gavares commented 1 year ago

Wow, thanks for the quick response @justcoon