多个log4j.properties文件

问题描述:

这似乎不是一个有效的问题,但是我在这里有一个要求.下面是我的项目结构:

This might not seem a valid question but I have a requirement here. Below is my project structure:

common (built as a jar)
module-1 (war, includes common.jar in its classpath)
module-2 (war, includes common.jar in its classpath)
module-3 (war, includes common.jar in its classpath)
module-4 (war, includes common.jar in its classpath)

部署如下:

模块1和模块2在一台服务器上,模块3和模块4在另一台服务器上.

module-1 and module-2 is on one server and module-3 and module-4 on another.

要求是有两个单独的日志文件(每个服务器一个).因此,实现此目的的方法是将log4j.properties(肯定使用不同的名称)放在通用模块中,然后将所需的属性文件复制到相应服务器的conf文件夹中.

The requirement is to have two separate log files(one for each server). So, the way to achieve this is put the log4j.properties (definitely with different names) in the common module and copy the required properties file to the respective server's conf folder.

我不确定,是否可以使用其他名称的日志记录属性文件,如果可以的话,请指导我.

I am not sure, if I can have the logging properties file with different names, if it is possible, please help me with a direction to do so.

编辑为了简化此过程,如果任何人都可以告诉我log4j.properties文件是否可以使用其他名称以及如何将其加载到服务器,我将能够实现其余的.

EDIT To make this easier, if you anyone can tell me if I can use a different name for the log4j.properties file and how to load it to the server, I would be able to achieve the rest.

谢谢.

我终于解决了这个问题,是的,对于log4j配置属性文件,可以使用不同于log4j.properties的名称.

I finally fixed this issue, and yes there is a way of using a name different than log4j.properties for the log4j configuration properties file.

我们可以命名为mylog4j.properties.为了使JVM能够做到这一点,我们需要将参数传递给JVM,如下所示:

We can name it whatever we want say mylog4j.properties. For the JVM to pick this up we need to pass an argument to the JVM like below:

-Dlog4j.configuration=mylog4j.properties

使用eclipse运行应用程序时,可以通过运行运行配置->参数选项卡-> VM参数并添加属性来执行此操作 -Dlog4j.configuration=mylog4j.properties

When running applications using eclipse, you can do this by going to Run Configurations -> Arguments Tab -> VM Arguments and add the property -Dlog4j.configuration=mylog4j.properties