Spark的日志配置

在測试spark计算时。将作业提交到yarn(模式–master yarn-cluster)上,想查看print到控制台这是imposible的。由于作业是提交到yarn的集群上,so 去yarn集群上看日志是非常麻烦的,但有特别想看下print的信息,方便调试或者别的目的

在Spark的conf文件夹下,把log4j.properties.template改动为log4j.properties。原来的内容例如以下:

#Set everything to be logged to the console
log4j.rootCategory=INFO, 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

#Settings to quiet third party logs that are too verbose
log4j.logger.org.spark-project.jetty=WARN
log4j.logger.org.spark-project.jetty.util.component.AbstractLifeCycle=ERROR
log4j.logger.org.apache.spark.repl.SparkIMain$exprTyper=INFO
log4j.logger.org.apache.spark.repl.SparkILoop$SparkILoopInterpreter=INFO

把log4j.rootCategory=INFO, console改为log4j.rootCategory=WARN, console就可以抑制Spark把INFO级别的日志打到控制台上。

假设要显示全面的信息。则把INFO改为DEBUG。

假设希望一方面把代码中的println打印到控制台,还有一方面又保留spark 本身输出的日志,能够将它输出到日志文件里

log4j.rootCategory=INFO, console,FILE
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

# Settings to quiet third party logs that are too verbose
log4j.logger.org.eclipse.jetty=WARN
log4j.logger.org.eclipse.jetty.util.component.AbstractLifeCycle=ERROR
log4j.logger.org.apache.spark.repl.SparkIMain$exprTyper=INFO
log4j.logger.org.apache.spark.repl.SparkILoop$SparkILoopInterpreter=INFO

log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.Threshold=DEBUG
log4j.appender.FILE.file=/home/hadoop/spark.log
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[%-5p] [%d{yyyy-MM-dd HH:mm:ss}] [%C{1}:%M:%L] %m%n
# spark
log4j.logger.org.apache.spark=INFO

上面的操作,spark的日志一方面打印到控制台,一方面写入到/home/hadoop/spark.log中了。这是日志的继承特性。后面再来改进。眼下把log4j.rootCategory=INFO, console。FILE改为log4j.rootCategory=INFO, FILE就可以

    原文作者:spark
    原文地址: https://www.cnblogs.com/zfyouxi/p/5261305.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞