log4j2问题。无法在控制台或文件中记录任何东西。

时间:2022-08-28 21:50:09

I just updated from log4j 1.x to log4j2. Every thing was working fine in 1st version. Now after updating to log4j2 its not logging any thing . i am pasting my code below. any one please help me out

我刚刚从log4j 1更新。x log4j2。在第一个版本中,一切都很正常。现在更新到log4j2后,它不会记录任何东西。我正在粘贴下面的代码。请帮我一下。

This are my dependencies

这是我的依赖

      <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-1.2-api</artifactId>
        <version>2.0-beta9</version>
        <type> jar</type>

    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.0-beta9</version>
        <type> jar</type>

    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.0-beta9</version>
        <type> jar</type>

    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-jcl</artifactId>
        <version>2.0-beta9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.0-beta9</version>
    </dependency>                                                
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-taglib</artifactId>
        <version>2.0-beta9</version>
    </dependency>

this is my log4j2.xml

这是我log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>

<Configuration status="warn" name="MyApp" packages="">
    <Appenders>
        <console name="Console" target="SYSTEM_OUT" includeLocation="true">
        <PatternLayout pattern="%d %-5p [%t] [%c:%L] %m%n"/>

        </console>
        <RollingRandomAccessFile name="Rolling" fileName="${sys:DOC_ROOT}/logs/UILogs-${sys:SERVER_NAME}-${sys:SERVER_ID}-${sys:SERVER_TYPE}.log"
                                 filePattern="${sys:DOC_ROOT}/logs/UILogs-${sys:SERVER_NAME}-${sys:SERVER_ID}-${sys:SERVER_TYPE}-%d{yyyy-MM-dd}.log.gz">
            <PatternLayout pattern="%d %-5p [%t] [%c:%L] %m%n"/>
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="250 MB"/>
            </Policies>
            <DefaultRolloverStrategy max="180" compressionLevel="9"/>
        </RollingRandomAccessFile>



        <Async name="dev">
            <AppenderRef ref="DevSMTP" level="fatal"/>
            <AppenderRef ref="Console" level="debug"/>
            <AppenderRef ref="Rolling" level="debug"/>
        </Async>
        <Async name="test">
            <AppenderRef ref="TestSMTP" level="fatal"/>
            <AppenderRef ref="Console" level="debug"/>
            <AppenderRef ref="Rolling" level="debug"/>
        </Async>  
        <Async name="prod">
            <AppenderRef ref="ProdSMTP" level="fatal"/>
            <AppenderRef ref="Console" level="info"/>
            <AppenderRef ref="Rolling" level="info"/>
        </Async>
        <Async name="local">
            <AppenderRef ref="DevSMTP" level="fatal"/>
            <AppenderRef ref="Console" level="debug"/>
            <AppenderRef ref="Rolling" level="debug"/>
        </Async>
        <Async name="">
            <AppenderRef ref="ProdSMTP" level="fatal"/>
            <AppenderRef ref="Console" level="info"/>
            <AppenderRef ref="Rolling" level="info"/>
        </Async>
        <Async name="">
            <AppenderRef ref="TestSMTP" level="fatal"/>
            <AppenderRef ref="Console" level="debug"/>
            <AppenderRef ref="Rolling" level="debug"/>
        </Async> 
        <Async name="">
            <AppenderRef ref="ProdSMTP" level="fatal"/>
            <AppenderRef ref="Console" level="info"/>
            <AppenderRef ref="Rolling" level="info"/>
        </Async>
        <Async name="lib">
            <AppenderRef ref="Console" level="info"/>
            <AppenderRef ref="Rolling" level="info"/>
        </Async> 

    </Appenders>  

    <Loggers>
        <Root level="debug" additivity="false">
            <AppenderRef ref="${sys:SERVER_TYPE}"/>
        </Root>        
        <root level="error">
      <appender-ref ref="Console"/>
    </root>
        <Logger name="org.apache.ibatis" additivity="false">
            <AppenderRef ref="lib"/>
        </Logger>
        <Logger name="java.sql" additivity="false">
            <AppenderRef ref="lib"/>
        </Logger>
         <Logger name="RollingRandomAccessFile" additivity="true">
            <AppenderRef ref="Rolling"/>
        </Logger>
        <logger name="com.foo.Bar" level="trace">
  <appender-ref ref="Console"/>
</logger>

</Configuration>

2 个解决方案

#1


2  

There are a couple of things to fix in the configuration:

在配置中有一些事情需要修正:

Dependencies:

依赖关系:

  • There is a space ' ' character between <type> and jar. (Not sure if this causes any problem).
  • 和jar之间有一个空格'的字符。(不确定这是否会引起任何问题)。

Log4j2.xml configuration:

Log4j2。xml配置:

  • There are three Async appenders without a name. They MUST have names.
  • 有三个异步appenders没有名称。他们必须有名字。
  • There are two root appenders. There can be only ONE root appender in a configuration, so you need to remove one of them.
  • 有两个根appenders。在配置中只能有一个根appender,所以您需要删除其中一个。
  • Several Loggers do not have a level defined. If your intention is for the log level filtering to be done by the appenders, I recommend that you ensure that ALL events are passed to the appenders: I recommend you specify level TRACE on these loggers.
  • 一些日志记录器没有定义级别。如果您的意图是为appenders所做的日志级别过滤,我建议您确保将所有事件传递给appenders:我建议您在这些日志记录器上指定级别跟踪。
  • The <Loggers> element does not have a closing </Loggers> tag. This may be the biggest problem.
  • < logger >元素没有关闭 标签。这可能是最大的问题。

#2


0  

Are you receiving any related error? for example if it's the error: "ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogge" try this link to solve your logging issues.

你是否有任何相关的错误?例如,如果是错误:“error StatusLogger无法找到日志实现,使用SimpleLogge”尝试这个链接来解决您的日志问题。

#1


2  

There are a couple of things to fix in the configuration:

在配置中有一些事情需要修正:

Dependencies:

依赖关系:

  • There is a space ' ' character between <type> and jar. (Not sure if this causes any problem).
  • 和jar之间有一个空格'的字符。(不确定这是否会引起任何问题)。

Log4j2.xml configuration:

Log4j2。xml配置:

  • There are three Async appenders without a name. They MUST have names.
  • 有三个异步appenders没有名称。他们必须有名字。
  • There are two root appenders. There can be only ONE root appender in a configuration, so you need to remove one of them.
  • 有两个根appenders。在配置中只能有一个根appender,所以您需要删除其中一个。
  • Several Loggers do not have a level defined. If your intention is for the log level filtering to be done by the appenders, I recommend that you ensure that ALL events are passed to the appenders: I recommend you specify level TRACE on these loggers.
  • 一些日志记录器没有定义级别。如果您的意图是为appenders所做的日志级别过滤,我建议您确保将所有事件传递给appenders:我建议您在这些日志记录器上指定级别跟踪。
  • The <Loggers> element does not have a closing </Loggers> tag. This may be the biggest problem.
  • < logger >元素没有关闭 标签。这可能是最大的问题。

#2


0  

Are you receiving any related error? for example if it's the error: "ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogge" try this link to solve your logging issues.

你是否有任何相关的错误?例如,如果是错误:“error StatusLogger无法找到日志实现,使用SimpleLogge”尝试这个链接来解决您的日志问题。