How to import StructuredArgument for structured logging in scala using slf4j and logback

喜你入骨 提交于 2021-01-28 09:53:04

问题


This is probably a stupid question, but my scala knowledge is a bit lacking. I'm trying to implement structured logging in scala, and we're using slf4j/logback/logstash. I came across the following post: How does SLF4J support structured logging Which describes how to do it:

import static net.logstash.logback.argument.StructuredArguments.*;

/*
 * Add "name":"value" ONLY to the JSON output.
 *
 * Since there is no parameter for the argument,
 * the formatted message will NOT contain the key/value.
 *
 * If this looks funny to you or to static analyzers,
 * consider using Markers instead.
 */
logger.info("log message", keyValue("name", "value"));

Obviously this is java code, not scala. I've converted it over, but I can't get it to find net.logstash.logback.argument.StructuredArguments.KeyValue. I'm guessing this is because it's not being included in the build, but this is where I'm tripping up.

I'm using sbt, and I'm including what I expect the package to be:

"net.logstash.logback" %% "logstash-logback-encoder" % VersionOf.`logstash`

However sbt cannot find that package (version is 1.2.1). What's also confusing me is that our other dependencies for logback are pulled from the group id: ch.qos.logback. I don't really understand what ch.qos.logback is and why it's different from net.logstash.logback.

Long story short, what package do I need to import with sbt so that I can use StructuredArguments/KeyValues for my logging?

来源:https://stackoverflow.com/questions/63471153/how-to-import-structuredargument-for-structured-logging-in-scala-using-slf4j-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!