在 spark 应用程序中捆绑到 jar 中的 log4j 属性文件被忽略 [英] log4j properties file bundled into jar in spark app is ignored

查看:23
本文介绍了在 spark 应用程序中捆绑到 jar 中的 log4j 属性文件被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 src/resources 中读取自定义 log4j.properties,但这不起作用

I need to read a custom log4j.properties from src/resources and this is not working

try{
  val  inStream :InputStream= className.this.getClass.getClassLoader.getResourceAsStream("log4j.properties");

  logCfgProps.load(inStream)

} catch {
  case e: Throwable=>
    e.printStackTrace()
    log.error("log.properties file not present")
}

PropertyConfigurator.configure(logCfgProps)

表示jar中捆绑的log4j被忽略.

meaning that the log4j bundled in the jar is ignored.

我无法触摸 spark home 的 conf 目录中的 log4j 属性.

I cannot touch the log4j properties in the conf directory in the spark home.

还有哪些其他选择?

编辑一定有什么问题(在类路径中?)既然这样做了

EDIT There must be something wrong (in the classpath ?) since doing this

val resource:URL = Thread.currentThread().getContextClassLoader()
  .getResource("log4j.properties");
System.out.println("resource = " + resource); 

它指向我无法修改的conf目录中的log4j,我需要忽略它.

It points to the log4j in the conf directory that I cannot modify and that I need to ignore.

怎么做?

推荐答案

  1. 你可以给你的文件取另一个名字(也可以在代码中使用),所以不会和conf/log4j.properties冲突.

您可以使用 ClassLoader.getResources("log4j.properties") 并选择你想要的.

You can get all resources with the given name on the classpath using ClassLoader.getResources("log4j.properties") and choose which one you want.

这篇关于在 spark 应用程序中捆绑到 jar 中的 log4j 属性文件被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆