gpt4 book ai didi

erlang - 在 Elixir 伞形应用程序中,应该在哪里添加记录器后端应用程序作为依赖项?

转载 作者:行者123 更新时间:2023-12-04 08:47:30 24 4
gpt4 key购买 nike

我有一个 Elixir 伞式应用程序。伞下的应用程序使用Logger .我想为 :logger 添加一个后端 ( logger_logstash_backend )应用。所以,我需要在 deps 中添加它作为依赖项。混合文件中的功能。

在伞形应用程序最外层的 mix 文件中,deps 的文档函数状态:

Dependencies listed here are available only for this project and cannot be accessed from applications inside the apps folder



这意味着我必须将后端模块添加为伞下每个应用程序的依赖项。但是,这样做会导致几个问题:
  • 以后将单个应用程序作为单独的库移出变得更加困难。
  • 伞下的各个应用程序实际上并不依赖于自定义 :logger后端模块。他们可以使用默认 :console后端。但我只想为 prod 环境提供一个额外的后端。因此,我不得不将依赖项单独添加到每个应用程序中,这更像是一个跨应用程序问题。

  • 你知道更好的策略吗?它是什么?

    最佳答案

    每个应用程序都应该有自己的依赖项和配置。

    你提到的问题:

    1. It becomes harder to move out the individual applications as separate libraries later.


    如果您在每个应用程序中都有配置,这实际上可以更轻松地将单个应用程序移出伞式应用程序。如 Elixir guides 中所述,您只需将应用程序移出 apps/目录。

    1. The individual applications under the umbrella are not actually dependent on the custom :logger backend module. They're okay with default :console backend. But I want to have an additional backend only for prod environment. Therefore, it's more of a cross-applications concern where I'm forced to add the dependency to each application individually.


    如果仅在生产环境中需要自定义记录器后端,则应用程序只能将此配置添加到 config/prod.exs文件并仅在 prod 环境中使用它。

    关于erlang - 在 Elixir 伞形应用程序中,应该在哪里添加记录器后端应用程序作为依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46368633/

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