001.Spark的日誌配置

參考地址:Spark的日誌配置 apache


在測試spark計算時,將做業提交到yarn(模式–master yarn-cluster)上,想查看print到控制檯這是imposible的,由於做業是提交到yarn的集羣上,so 去yarn集羣上看日誌是很麻煩的,但有特別想看下print的信息,方便調試或者別的目的 app

在Spark的conf目錄下,把log4j.properties.template修改成log4j.properties,原來的內容以下: eclipse

#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。 oop

若是但願一方面把代碼中的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便可 ui

相關文章
相關標籤/搜索