Weld-SE没有使用log4j2进行日志记录

时间:2014-08-31 10:45:57

标签: log4j2 weld-se

我使用weld-se和log4j2作为记录器。但我无法从韦尔德得到任何东西。其他日志记录工作正常。

库:

    <dependency>
        <groupId>org.jboss.weld.se</groupId>
        <artifactId>weld-se-core</artifactId>
        <version>2.2.4.Final</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.0.2</version>
    </dependency>

log4j2.xml

<Configuration status="INFO">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <logger name="org.jboss.weld.level" level="debug"/>
        <Root level="debug">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>

感谢您的建议。

1 个答案:

答案 0 :(得分:3)

尝试使用Log4j 2的SLF4J实现:

<dependency>
    <groupId>org.jboss.weld.se</groupId>
    <artifactId>weld-se-core</artifactId>
    <version>2.2.4.Final</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.0.2</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.0.2</version>
</dependency>

JBoss Weld使用类org.jboss.logging.LoggerProviders来查找日志记录提供程序。如果您看到此类的code,则会看到查找系统属性 org.jboss.logging.provider

您可以添加到jvm参数,也可以模拟它。 e.g:

public class App {

    static {
        System.setProperty("org.jboss.logging.provider", "slf4j");
    }

    public static void main(String[] args) {
        Weld weld = new Weld();
        WeldContainer container = weld.initialize();
        // Do something
        weld.shutdown();
    }

}