gpt4 book ai didi

java - 如何在 logback.xml 中指定绝对路径?

转载 作者:行者123 更新时间:2023-11-30 10:25:38 24 4
gpt4 key购买 nike

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<include resource="/opt/logback/logback_mobile.xml"></include>
</configuration>

Could not find resource corresponding to [/opt/logback/logback_mobile.xml]

但文件确实存在。

如何在 logback.xml 中指定绝对路径?

最佳答案

在 logback.xml 文件中包含资源时,您有三种选择:

As a file:

To include a file use the file attribute. You can use relative paths but note that the current directory is defined by the application and is not necessarily related to the path of the configuration file.

As a resource:

To include a resource, i.e a file found on the class path, use the resource attribute.<include resource="includedConfig.xml"/>

As a URL:

To include the contents of a URL use the url attribute.<include url="http://some.host.com/includedConfig.xml"/>

来自docs .

因此,您可以使用相对于应用程序运行位置的文件路径,或者您可以使用类路径引用,或者您可以使用 URL,但不支持绝对文件路径。

要包含此文件:/opt/logback/logback_mobile.xml我认为您的选择是:

  • 使用相对引用,假设您的应用程序从 /opt/app/myservice 开始运行那么您的包含声明将是:<include resource="../../logback/logback_mobile.xml"></include> .
  • 包括/opt/logback/在您的应用程序的类路径上,然后将包含声明更改为 <include resource="logback_mobile.xml"></include> .
  • 服务 logback_mobile.xml来自 Web 服务器,然后通过 URL 包含它。

关于java - 如何在 logback.xml 中指定绝对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46090042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com