简体   繁体   English

如何在项目之间共享logback.xml

[英]How to share logback.xml between projects

I have a couple projects and I'm wondering the best way to share logback configurations between them. 我有几个项目,我想知道在它们之间共享日志配置的最佳方法。 The setup looks something like this: 设置看起来像这样:

Physical Machine 1
    Project 1
    Project 2
    Project 3

Physical Machine 2
    Project 1
    Project 4

To avoid duplication, I don't want to stick a logback.xml in each projects resources directory. 为避免重复,我不想在每个项目的资源目录中粘贴logback.xml。 Should I bundle the logback.xml as another project and make it a dependency for each of the projects? 我是否应该将logback.xml捆绑为另一个项目,并使其成为每个项目的依赖项? Or just place it somewhere on the hard drive and have each project read in the logback.xml on startup? 或者只是将其放置在硬盘驱动器上的某个位置,并在启动时在logback.xml中读取每个项目? Or something else? 或者是其他东西?

Also for development, they are all in the same JVM, so sharing a logback-test.xml and not reading from disk would be nice. 同样为了开发,它们都在同一JVM中,因此共享logback-test.xml而不从磁盘读取将是很好的。

I generally bundle configuration files as a standalone project so that it can be used across multiple projects. 我通常将配置文件捆绑为一个独立的项目,以便可以在多个项目中使用。

I think the principal argument relies on versionning and how easy it's going to be if it's a dependency. 我认为主要论点依赖于版本控制,如果它是依赖项,它将变得多么容易。 On the file system you'd have to keep several versions of the file in subdirectories and it could quickly become messy. 在文件系统上,您必须将文件的多个版本保留在子目录中,这样很快就会变得混乱。

If you're using Maven, here's a link which could help you. 如果您使用的是Maven,则以下链接可以为您提供帮助。

Here is the Logback Configuratrion Chapter in the online manual. 这是在线手册中的“ Logback配置”一章

When Logback is starting up, it attempts to load a logback configuration file from the classpath. Logback启动时,它将尝试从类路径中加载Logback配置文件。

A solution to your question is to store the shared logback.xml file in a directory that is in the classpath of each of the projects. 您的问题的解决方案是将共享的logback.xml文件存储在每个项目的类路径中的目录中。

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

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