如何使用gradle禁用使用spark / scala项目的日志记录?

时间:2017-09-20 02:46:40

标签: scala apache-spark gradle

我正在使用带有gradle的IntelliJ来构建spark项目。我尝试了多种方法来禁用日志记录,但无济于事。

以下是我尝试过的一些事情。 1.使用以下配置

在src / main / resources下添加log4j.properties



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


# Change this to set Spark log level
log4j.logger.org.apache.spark=WARN

# Silence akka remoting
log4j.logger.Remoting=WARN

# Ignore messages below warning level from Jetty, because it's a bit verbose
log4j.logger.org.eclipse.jetty=WARN


# 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=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




  1. 在创建sparkSession之前和之后添加这些。
  2. 
    
    Logger.getLogger("org").setLevel(Level.OFF)
    Logger.getLogger("akka").setLevel(Level.OFF)
    Logger.getLogger("spark").setLevel(Level.OFF)
    LogManager.getRootLogger.setLevel(Level.OFF)
    
    
    

    1. 创建sparkSession
    2. 时添加此项

      
      
      val spark: SparkSession = SparkSession.builder()
        .appName("test").master("local")
        .enableHiveSupport()
        .getOrCreate()
      spark.sparkContext.setLogLevel("OFF")
      
      
      

      我正在使用mac OS运行IntelliJ, scalaVersion = 2.11.8 sparkVersion = 2.1.1

      请帮助我,我在互联网上上下打量,但仍无法找到有效的内容

      万分感谢! 可能。

0 个答案:

没有答案