【问题标题】:log4j.properties file not found on classpath or ignoredlog4j.properties 文件在类路径中找不到或被忽略
【发布时间】:2017-12-20 15:22:19
【问题描述】:

我想用 log4j 登录 maprDB 一个 spark 作业。我已经编写了一个自定义附加程序,这里是我的 log4j.properties:

log4j.rootLogger=INFO,标准输出

log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

log4j.appender.MapRDB=com.datalake.maprdblogger.Appender

log4j.logger.testest=警告,MapRDB

放到src/main/resources目录

这是我的主要方法:

object App {
    val log: Logger = org.apache.log4j.LogManager.getLogger(getClass.getName)

    def main(args: Array[String]): Unit = {
        // custom appender
        LogHelper.fillLoggerContext("dev", "test", "test", "testest", "")
        log.error("bad record.")
    }
}

当我在没有任何配置的情况下运行 spark-submit 时,什么也没有发生。就像我的 log4j.properties 不在这里一样。

如果我手动部署我的 log4j.properties 文件并添加选项:

--conf spark.driver.extraJavaOptions=-Dlog4j.configuration=file:/PATH_TO_FILE/log4j.properties

--conf spark.executor.extraJavaOptions=-Dlog4j.configuration=file:/PATH_TO_FILE/log4j.properties

效果很好。为什么没有这些选项它就不起作用?

【问题讨论】:

  • 您使用什么构建工具?路径不应该是src/main/resources吗?
  • 我也认为log4j.appender.stdout.Target(大写)应该是log4j.appender.stdout.target(小写)。
  • 如果我明确设置路径,log4j.properties 工作得很好。问题是火花和他的 log4j.properties 是首先选择的。
  • 使用 -Dlog4j.debug 并查看 log4j 搜索属性的位置。
  • $SPARK_HOME/conf/log4j.properties

标签: scala apache-spark logging log4j mapr


【解决方案1】:

“spark.driver.extraJavaOptions”:

默认值为:(无)

A string of extra JVM options to pass to the driver. For instance, GC settings or other logging. Note that it is illegal to set maximum heap size (-Xmx) settings with this option. Maximum heap size settings can be set with spark.driver.memory in the cluster mode and through the --driver-memory command-line option in the client mode. 

注意:在客户端模式下,这个配置不能直接在你的应用程序中通过 SparkConf 设置,因为此时驱动程序 JVM 已经启动。相反,请通过 --driver-java-options 命令行选项或在您的默认属性文件中进行设置。

[请参阅此链接了解更多详情: https://spark.apache.org/docs/latest/configuration.html]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-27
    • 2023-03-04
    • 2012-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    相关资源
    最近更新 更多