Set Log4j 2 property file location without System.setProperty or classpath?

ptstone

i'm moving from Log4j 1.2 to Log4j 2.8 and am looking for a way to set the location of the property file in my programs. In 1.2, this was done using

PropertyConfigurator.configure("path/to/log4j.properties");

However, reading the documentation, the config via property file in 2.8 seems to be restricted to
a) located in classpath or
b) via System property (see 1)

Since i have some applications where part of the system has its own configuration and needs to load it on demand, i wonder whether there is a way to config the Logmanager during runtime using a properties file?

Vikas Sachdeva

There is one more way to specify log4j2 configuration file location -

org.apache.logging.log4j.core.config.Configurator.initialize(null, "path/to/log4j2.properties");

Only point of precaution is that the Configurator class is not part of the public API. So, it might get removed in future version.

Above code is working in log4j2 version 2.8.2 which is latest.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Log4j JDK Logging adapter: Apply LogManager system property late in the startup process

分類Dev

How to configure Log4j (1 or 2) to use custom log file name while code against Slf4j

分類Dev

How to solve - ERROR StatusLogger No Log4j 2 configuration file found

分類Dev

Properly initialize log4j system

分類Dev

System.setPropertyまたはクラスパスなしでLog4j2プロパティファイルの場所を設定しますか?

分類Dev

Mybatis log4j how to confiure log4j to print sql log to file

分類Dev

Java/JSP log4j:WARN Please initialize the log4j system properly

分類Dev

Set File Name to Property

分類Dev

log4j 1.xとlog4j 2の混在

分類Dev

vsftpd log file location?

分類Dev

log4j - one file per run

分類Dev

Log4j2 file created but not log written

分類Dev

Log4j 2JSON構成

分類Dev

log4j2と同等のlog4J setSyslogHost(...)

分類Dev

Log4J 1.2 PropertyConfigurator-> Log4J2

分類Dev

log4j 1.2からlog4j2への移行

分類Dev

setting property of nsobject subclass by means of selector setProperty

分類Dev

Go: Need to set property but without pointer receiver?

分類Dev

Log4j2 - current date file append not working

分類Dev

Spring properties file vs system property

分類Dev

Spring properties file vs system property

分類Dev

log4j対System.out.println-ロガーの利点?

分類Dev

Log4j path Configuration Error In J2EE Web Application

分類Dev

System.setPropertyおよびSystem.getProperty

分類Dev

log4j2 java.lang.NoClassDefFoundError:org / apache / logging / log4j / LogManager

分類Dev

log4j StringMatchFilterをlog4j2に変換する方法は?

分類Dev

log4jからlog4j2のカスタムRollingPolicy

分類Dev

How to lookup property parameter in web app for log4j2?

分類Dev

onInitのODataV2 SetProperty

Related 関連記事

  1. 1

    Log4j JDK Logging adapter: Apply LogManager system property late in the startup process

  2. 2

    How to configure Log4j (1 or 2) to use custom log file name while code against Slf4j

  3. 3

    How to solve - ERROR StatusLogger No Log4j 2 configuration file found

  4. 4

    Properly initialize log4j system

  5. 5

    System.setPropertyまたはクラスパスなしでLog4j2プロパティファイルの場所を設定しますか?

  6. 6

    Mybatis log4j how to confiure log4j to print sql log to file

  7. 7

    Java/JSP log4j:WARN Please initialize the log4j system properly

  8. 8

    Set File Name to Property

  9. 9

    log4j 1.xとlog4j 2の混在

  10. 10

    vsftpd log file location?

  11. 11

    log4j - one file per run

  12. 12

    Log4j2 file created but not log written

  13. 13

    Log4j 2JSON構成

  14. 14

    log4j2と同等のlog4J setSyslogHost(...)

  15. 15

    Log4J 1.2 PropertyConfigurator-> Log4J2

  16. 16

    log4j 1.2からlog4j2への移行

  17. 17

    setting property of nsobject subclass by means of selector setProperty

  18. 18

    Go: Need to set property but without pointer receiver?

  19. 19

    Log4j2 - current date file append not working

  20. 20

    Spring properties file vs system property

  21. 21

    Spring properties file vs system property

  22. 22

    log4j対System.out.println-ロガーの利点?

  23. 23

    Log4j path Configuration Error In J2EE Web Application

  24. 24

    System.setPropertyおよびSystem.getProperty

  25. 25

    log4j2 java.lang.NoClassDefFoundError:org / apache / logging / log4j / LogManager

  26. 26

    log4j StringMatchFilterをlog4j2に変換する方法は?

  27. 27

    log4jからlog4j2のカスタムRollingPolicy

  28. 28

    How to lookup property parameter in web app for log4j2?

  29. 29

    onInitのODataV2 SetProperty

ホットタグ

アーカイブ