捆绑到罐子火花应用log4j属性文件将被忽略

捆绑到罐子火花应用log4j属性文件将被忽略

本文介绍了捆绑到罐子火花应用log4j属性文件将被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要读的src /资源自定义log4j.properties,这是行不通的。

  {尝试
  VAL inStream中:为InputStream = className.this.getClass.getClassLoader.getResourceAsStream(log4j.properties);  logCfgProps.load(插播广告)} {抓
  方案E:可抛出=>
    e.printStackTrace()
    log.error(log.properties文件中没有present)
}PropertyConfigurator.configure(logCfgProps)

这意味着在罐子捆绑log4j的被忽略。

我不能在家里火花conf目录触摸log4j属性。

什么其他选择?

编辑
一定有什么东西错了(在classpath中?)
因为这样做

  VAL资源:URL = Thread.currentThread()getContextClassLoader()
.getResource(log4j.properties);
的System.out.println(资源=+资源);

它指向的conf目录下的log4j的,我不能修改,而我需要忽略。

该怎么做?


解决方案

  1. 您可以只给另一名到您的文件(并在code。使用它),所以与的conf / log4j.properties没有冲突


  2. 您可以得到所有的资源用在类路径中给定的名称 中ClassLoader.getResources(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)

meaning that the log4j bundled in the jar is ignored.

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

What are the other options?

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

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

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

How to do that?

解决方案
  1. You can just give another name to your file (and using it in the code as well), so there is no conflict with conf/log4j.properties.

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

这篇关于捆绑到罐子火花应用log4j属性文件将被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 09:42