简体   繁体   English

我将 spring 引导应用程序更改为 spring mvc 但我的 log4j2.xml 不起作用?

[英]I changed spring boot app to spring mvc but my log4j2.xml is not working?

I change spring boot to spring MVC , but I can't see any log information in my log file but it populates in the console .我将 spring 引导更改为 spring MVC ,但在我的日志文件中看不到任何日志信息,但它会填充在控制台中 Please let me know the changes I need to make in the log4j2.xml file so that log info will be saved to log files.请让我知道我需要在 log4j2.xml 文件中进行的更改,以便将日志信息保存到日志文件中。

what is monitorinterval=30 in the below XML file?以下 XML 文件中的monitorinterval=30是什么?

Thank you soo much for the response非常感谢您的回复

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
    <Properties>
        <Property name="LOG_PATTERN">
            %d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} --- [%15.15t] %-40.40c{1.} : %m%n%ex
        </Property>
    </Properties>

    <Appenders>
        <Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="${LOG_PATTERN}"/>
        </Console>

        <!-- Rolling File Appender -->
        <RollingFile name="FileAppender" fileName="logs/prism.log"
                     filePattern="logs/prism-%d{yyyy-MM-dd}-%i.log.zip">
            <PatternLayout>
                <Pattern>${LOG_PATTERN}</Pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="5 MB"/>
            </Policies>
            <DefaultRolloverStrategy max="10"/>
        </RollingFile>

    </Appenders>

    <Loggers>
        <Logger name="com.heymath" level="debug"
                additivity="false">
            <AppenderRef ref="ConsoleAppender"/>
            <AppenderRef ref="FileAppender"/>
        </Logger>

        <Root level="info">
            <AppenderRef ref="ConsoleAppender"/>
            <AppenderRef ref="FileAppender"/>
        </Root>
    </Loggers>
</Configuration>

monitorInterval=30 tells Log4j2 to check every 30 seconds to see if the logging configuration has changed and reconfigure if it has. monitorInterval=30 告诉 Log4j2 每 30 秒检查一次日志配置是否已更改,如果已更改则重新配置。

I see nothing obviously wrong with your configuration.我看不出你的配置有什么明显的问题。 It should be logging all info, warn, error and fatal messages to the file and console.它应该将所有信息、警告、错误和致命消息记录到文件和控制台。 Debug messages from com.heymath loggers should be going there as well.来自 com.heymath 记录器的调试消息也应该在那里。

I would suggest changing the status="WARN" to status="DEBUG" on the configuration element.我建议将配置元素上的 status="WARN" 更改为 status="DEBUG"。 If you do not see logs from log4j it means that your configuration file was not found and is not being used.如果您没有看到来自 log4j 的日志,则表示您的配置文件未找到且未被使用。 Instead, it is using the default configuration which logs errors to the console.相反,它使用将错误记录到控制台的默认配置。

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

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