在log4j配置之间切换

时间:2015-05-14 06:15:46

标签: java spring maven logging

我刚刚实施了Spring个人资料,在web.xml我添加了默认个人资料:

<context-param>
    <param-name>spring.profiles.default</param-name>
    <param-value>prod</param-value>
</context-param>

在我的applicationContext.xml我现在可以轻松切换使用哪个配置文件:

 <beans profile="dev">
        <context:property-placeholder location="classpath*:META-INF/spring/dev.properties"/>
    </beans>
    <beans profile="prod">
        <context:property-placeholder location="classpath*:META-INF/spring/prod.properties"/>
    </beans>

我已经mvn jetty:run总是使用开发配置文件:

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.2.10.v20150310</version>
    <configuration>
        <webAppConfig>
            <contextPath>/${project.artifactId}</contextPath>
            <sessionHandler implementation="org.eclipse.jetty.server.session.SessionHandler">
            <sessionManager implementation="org.eclipse.jetty.server.session.HashSessionManager">
            <!-- Disable url sessions using JSessionID -->                                              
            <sessionIdPathParameterName>none</sessionIdPathParameterName>
            </sessionManager>
            </sessionHandler>
        </webAppConfig>
        <httpConnector>
            <port>9091</port>
        </httpConnector>
            <systemProperties>
                <systemProperty>
                <name>spring.profiles.active</name>
                <value>dev</value>
            </systemProperty>
        </systemProperties>
    </configuration>
</plugin>

如何在不同的log4j配置之间切换?

我正在使用sl4j和log4j:

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${slf4j.version}</version>
    </dependency>

在开发中我登录到stdout并在生产中我登录stdoutqueue(队列是rabbitMQ)?

显然当log4j启动时Spring还没有加载(没有双关语意),所以看起来Spring的配置文件已经出来了。

如何在不同的log4j配置之间轻松切换 - log4j-dev.propertieslog4j-prod.properties

0 个答案:

没有答案
相关问题