使用storm配置logback

unguejic  于 2021-06-24  发布在  Storm
关注(0)|答案(1)|浏览(361)

我有一个风暴项目,我已经添加了一些自定义的logback配置使用 logback.xml (添加了将日志写入索引的配置)。当我构建jar并将其部署到集群上时,我得到了这个类的多个绑定错误 StaticLoggerBinder.class 因为它同时存在于我的jar和storm自己的依赖列表中。下面是错误

SLF4J: Found binding in [jar:file:/usr/lib/storm/apache-storm-1.2.2/lib/log4j-slf4j-impl-2.8.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/app/test/test-storm-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/org/slf4j/impl/StaticLoggerBinder.class]

这导致我的任何自定义配置都无法获取。当我从storm的 lib 文件夹,我的 logback.xml 配置被反映,我的日志被写入索引,没有任何问题。在开始部署拓扑时,我还会看到这些日志,其中显示了我添加的配置

22:05:13,818 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/app/test/test-storm-0.0.55-SNAPSHOT-jar-with-dependencies.jar!/logback.xml]
22:05:13,839 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@19bb089b - URL [jar:file:/app/test/test-storm-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/logback.xml] is not of type file
22:05:14,094 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
22:05:14,097 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
22:05:14,102 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
22:05:14,125 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [com.splunk.logging.HttpEventCollectorLogbackAppender]
22:05:14,126 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [SPLUNK]
22:05:14,132 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.test] to INFO
22:05:14,132 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.test] to false
22:05:14,132 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [SPLUNK] to Logger[com.test]
22:05:14,133 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[com.test]
22:05:14,133 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
22:05:14,133 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT]
22:05:14,133 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.

但是,我不想走这条路,因为它无法维护,所以我决定使用 maven-shade-plugin 重新定位 org.slf4j.implorg.shaded.slf4j.impl . 现在,当我部署拓扑时,不再有多个绑定,但是我的 logback.xml 我的配置没有反映出来,也没有看到上面的消息。它可能会退回到使用不同的记录器。
如何在部署拓扑时反映配置?请帮忙(storm版本1.2.2)

htrmnn0y

htrmnn0y1#

风暴几年前从logback切换到log4j2。您可以通过storm/log4j2/worker.xml和storm/log4j2/cluster.xml文件配置log4j2。前者为您的拓扑以及工作jvm配置日志记录。
你应该把logback排除在你的胖jar之外。
也请看这个答案https://stackoverflow.com/a/50229035/8845188.

相关问题