Enclosing Class doesn't look well in json logs
RicoGit opened this issue · 4 comments
RicoGit commented
Add LogFormat.enclosingClass
into json logs like this:
private val logger =
Runtime.removeDefaultLoggers >>> consoleJson(default + LogFormat.enclosingClass)
Got:
{"text_content":" SOME FILENAME","timestamp":"2022-09-13T16:48:48.194359+04:00","level":"INFO","thread":"zio-fiber-6","message":"Process application"}
Expected:
{"file":"SOME FILENAME","location":"SOME LOCATION","line":27,"timestamp":"2022-09-13T16:48:48.194359+04:00","level":"INFO","thread":"zio-fiber-6","message":"Process application"}
davidlar commented
You should label enclosingClass if you want it to look good:
Runtime.removeDefaultLoggers >>> consoleJson(default + label("class", LogFormat.enclosingClass))
The reason is that we need structured logging to be able to output nice json. text_content is where everything else ends up when we have a non optimal format.
RicoGit commented
Thanks, I'll use custom formatted for this:
val location: LogFormat =
LogFormat.make { (builder, trace, _, _, _, _, _, _, _) =>
trace match {
case Trace(loc, _, line) => builder.appendText(s"$loc:$line")
case _ => builder.appendText("not-available")
}
}
private val logger =
Runtime.removeDefaultLoggers >>> consoleJson(LogFormat.default + LogFormat.label("location", location))
BTW Why location
is not logged by default, it seems to be a good idea.
justcoon commented
Hi @RicoGit,
do you have something else in relation to this issue? Thanks for answer. I like to close it if not, thanks.
RicoGit commented
Sure not, feel free.