在Spark中使用log4j2

栏目: 服务器 · 发布时间: 8年前

内容简介:在Spark中使用log4j2

Spark默认使用的log4j 1.2,它的配置文件就在Spark conf文件下,比如说/etc/spark/conf/log4j.properties.

如果我们想要在spark中使用log4j2,则情况比较复杂了。首先需要事先将log4j2的jar包复制到master节点和全部slave节点上, 将它的路径加入到Spark的classpath中,然后将log4j2.xml文件加入到Spark conf中。

把log42.xml放到resources文件夹中,将log4j2的jar事先复制到各个节点的log4j2文件夹中,那么运行spark程序的command就是:

spark-submit --files "/home/hadoop/resources/log4j2.xml" 
--driver-java-options=-Dlog4j.configurationFile=resources/log4j2.xml 
--conf "spark.executor.extraJavaOptions=-Dlog4j.configurationFile=resources/log4j2.xml"
--conf "spark.driver.extraClassPath=:/home/hadoop/log4j2/*" 
--conf "spark.executor.extraClassPath=:/home/hadoop/log4j2/*"

–files 会将log4j2.xml文件复制到yarn每个executor工作目录下面。注意Spark会为复制的文件创建相应的文件夹, 所以在executor中读取文件的路径是 resources/log4j2.xml 而不是 ./log4j2.xml .


以上所述就是小编给大家介绍的《在Spark中使用log4j2》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Visual Thinking

Visual Thinking

Colin Ware / Morgan Kaufmann / 2008-4-18 / USD 49.95

Increasingly, designers need to present information in ways that aid their audiences thinking process. Fortunately, results from the relatively new science of human visual perception provide valuable ......一起来看看 《Visual Thinking》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具