简体   繁体   English

从外部War文件中检索slf4j配置文件

[英]Retrieve slf4j config file from outside war file

Where can i store SLF4J configuration file so that all production and test environment may have access to it? 我可以在哪里存储SLF4J配置文件,以便所有生产和测试环境都可以访问它? I want to store the config file outside of the web app at an arbitrary location and retrieve that location upon startup. 我想将配置文件存储在Web应用程序外部的任意位置,并在启动时检索该位置。 I also want to allow for changing location of the config file so no classpath. 我也想允许更改配置文件的位置,所以没有classpath。 Im thinking about using getters and setters to retrieve the file path. 我正在考虑使用getter和setter来检索文件路径。

Any ideas?? 有任何想法吗??

slf4j is (for all practical purposes) just the API. slf4j(出于所有实际目的)仅是API。 You need a backend which does the actual work. 您需要一个可以完成实际工作的后端。

If you use logback you can ship a logback.xml file with your application which just includes another file. 如果您使用logback,则可以在您的应用程序中附带一个logback.xml文件,该文件仅包含另一个文件。 If I recall correctly the filename string can hold a ${variable} which you can then define outside your application. 如果我没记错的话,文件名字符串可以包含${variable} ,然后可以在应用程序外部进行定义。

See https://logback.qos.ch/manual/configuration.html#configFileProperty 请参阅https://logback.qos.ch/manual/configuration.html#configFileProperty

You may specify the location of the default configuration file with a system property named "logback.configurationFile". 您可以使用名为“ logback.configurationFile”的系统属性指定默认配置文件的位置。 The value of this property can be a URL, a resource on the class path or a path to a file external to the application. 该属性的值可以是URL,类路径上的资源或应用程序外部文件的路径。

java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM