hive启动过程中slf4j日志冲突导致控制台看到很多日志

背景描述

更改了hive的启动配置,发现hive启动的控制台页面,出现很多日志信息,而改动之前这些日志都是不可见的。初步怀疑是slf4j的实现类加载异常。

分析hive的加载的slf4j实现类

  1. 异常的slf4j 加载的class是Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/apps/ecm/service/hive/3.1.2-hadoop3.1-1.3.3/package/apache-hive-3.1.2-hadoop3.1-1.3.3-bin/lib/log4j-slf4j-impl-2.17.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/apps/ecm/service/hadoop/3.2.1-1.2.1/package/hadoop-3.2.1-1.2.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
  1. 正常的slf4j加载的实现类是:org.apache.logging.slf4j.Log4jLoggerFactory
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/apps/ecm/service/hive/3.1.2-hadoop3.1-1.3.3/package/apache-hive-3.1.2-hadoop3.1-1.3.3-bin/lib/log4j-slf4j-impl-2.17.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/apps/ecm/service/hadoop/3.2.1-1.2.1/package/hadoop-3.2.1-1.2.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

可以看到两个实现类加载不一样,导致日志打印异常。

查看实现类是被谁加载的

  1. 在hive的脚本中,更改HADOOP_OPTS,增加 HADOOP_OPTS = “$HADOOP_OPTS -verbose:class”,这样jvm中启动过程中,就会记录class被哪个jar加载的。配置完成之后,重新启动hivecli。

  2. 查看slf4j类加载过程
    正常的slf4j实现类加载过程,如下所示,可以看到这个是被hive所依赖的包,所以能够正常加载日志。

[Loaded org.apache.logging.slf4j.Log4jLoggerFactory from file:/opt/apps/ecm/service/hive/3.1.2-hadoop3.1-1.3.3/package/apache-hive-3.1.2-hadoop3.1-1.3.3-bin/lib/log4j-slf4j-impl-2.17.0.jar]

异常的hive的slf4j实现类加载过程

[Loaded org.slf4j.impl.Log4jLoggerFactory from /opt/apps/ecm/service/taihaodoctor/5.0.0-1.0.0/package/taihaodoctor-5.0.0-1.0.0/emr-agent/btrace-libs/mr/boot/agent-1.0.jar]

因为这个是新加的btrace-libs类,导致该类提前加载了非hive的使用log4j实现类,导致hive日志异常。

解决方案

StaticLoggerBinder的获取实现类的变量是static(static final String loggerFactoryClassStr = Log4jLoggerFactory.class.getName()),因此在类首次加载的时候就会创建这个变量。如果要想获取正确的实现类,也就是获取到正确的StaticLoggerBinder类,那么就要让想要的StaticLoggerBinder首先被加载到。那么如何做到呢?
答案是:更改类加载顺序,让hive依赖的StaticLoggerBinder类先加载。那么就需要更改classpath的方式。另外也要防止一些fat jar中存在StaticLoggerBinder导致也会被先加载

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值