想只显示ERROR日志。
方式1
代码里设置
val sc = new SparkContext(conf)
sc.setLogLevel("ERROR")
这个启动时,仍然会有一些其他日志.
方式2
log4j.properties文件设置
1.新建一个resource目录,在文件夹上右击,mark as reources root。


2.新建一个log4j.properties。将级别改为ERROR。
现在是全部其他日志都没了。
# Set everything to be logged to the console
log4j.rootCategory=ERROR, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n
# Set the default spark-shell log level to WARN. When running the spark-shell, the
# log level for this class is used to overwrite the root logger's log level, so that
# the user can have different defaults for the shell and regular Spark apps.
log4j.logger.org.apache.spark.repl.Main=ERROR
# Settings to quiet third party logs that are too verbose
log4j.logger.org.spark_project.jetty=ERROR
log4j.logger.org.spark_project.jetty.util.component.AbstractLifeCycle=ERROR
log4j.logger.org.apache.spark.repl.SparkIMain$exprTyper=ERROR
log4j.logger.org.apache.spark.repl.SparkILoop$SparkILoopInterpreter=ERROR
log4j.logger.org.apache.parquet=ERROR
log4j.logger.parquet=ERROR
# SPARK-9183: Settings to avoid annoying messages when looking up nonexistent UDFs in SparkSQL with Hive support
log4j.logger.org.apache.hadoop.hive.metastore.RetryingHMSHandler=FATAL
log4j.logger.org.apache.hadoop.hive.ql.exec.FunctionRegistry=ERROR
问题
有时候不起作用。因为程序加载了别的log4j.properties文件,就不加载自己配置的。
检验方式
加 VM options 查看 -Dlog4j.debug

会打印出,加载的什么地方的log4j.properties配置文件。
解决方案
指定log4j.properties文件位置。
加上一下代码。
org.apache.log4j.LogManager.resetConfiguration()
org.apache.log4j.PropertyConfigurator
.configure("/log4j.properties")
spark streaming
--conf spark.executor.extraJavaOptions="-Dlog4j.configuration=log4j.properties" \
--files conf/metrics.properties,conf/log4j.properties \
https://blog.youkuaiyun.com/anitinaj/article/details/84773423
Spark日志级别设置到ERROR详细教程
本文介绍了如何将Spark的日志级别设置为ERROR,包括两种方式:1) 在代码中设置,但可能仍有其他日志输出;2) 通过修改log4j.properties文件,但在某些情况下,程序可能加载了其他配置文件。当设置无效时,可以使用-Dlog4j.debug VM选项来检查加载的配置文件位置,并通过指定log4j.properties文件路径确保正确加载。最后,内容还提到了Spark Streaming的相关信息。

被折叠的 条评论
为什么被折叠?



