版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/datadev_sh/article/details/89400238
想只显示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 查看
会打印出,加载的什么地方的log4j.properties配置文件。
解决方案
指定log4j.properties文件位置。
加上一下代码。
org.apache.log4j.LogManager.resetConfiguration()
org.apache.log4j.PropertyConfigurator
.configure("/log4j.properties")