spring将日志写入控制台

x33g5p2x  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(210)

在我的SpringBoot应用程序中,我使用logback.xml编写日志,如下所示。预计产量约为2000万条。

private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MyJavaClass.class);
  logger.info("3000 characters strings to be logged go here.");

我的logback.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d [%thread] %-5level %-50logger{40} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>out.log</file>
        <encoder>
            <pattern>%d [%thread] %-5level %-50logger{40} - %msg%n</pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>out-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <maxFileSize>1MB</maxFileSize>
            <maxHistory>30</maxHistory>
            <totalSizeCap>10MB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
    </appender>

    <root level="INFO">
        <appender-ref ref="Console" />
        <appender-ref ref="RollingFile" />
    </root>
    <logger name="org.apache" level="WARN" />
    <logger name="httpclient" level="WARN" /> 
</configuration>

我的application.properties有:

logging.file.name=log.log
logging.pattern.rolling-file-name=MyApp-%d{yyyy-MM-dd}.%i.log
logging.file.max-size=1MB
logging.file.total-size-cap=10MB
logging.file.max-history=30
logging.file.clean-history-on-start=true

日志将写入log.log文件和控制台。
问:把2000万行放到控制台上是个好主意吗?这种方法是否会使系统负担过重,并且应该完全禁用控制台日志?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题