您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Spring Boot中将特定的类记录到另一个日志文件中

如何在Spring Boot中将特定的类记录到另一个日志文件中

如果需要这样做,则需要您自己的logback.xml文件

<configuration>

<!-- Normal debug log appender -->
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>debug.log</file>

    <encoder>
      <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    </encoder>
  </appender>

<appender name="virtuallab" type="ch.qos.logback.core.rolling.RollingFileAppender">
   <file value="Logs/virtuallab.log"/>
   <appendToFile value="true"/>
   <maxSizeRollBackups value="5"/>
   <maximumFileSize value="5MB"/>
   <rollingStyle value="Size"/>
   <staticLogFileName value="true"/>
   <encoder>
     <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
   </encoder>
</appender>

<!-- Setup the root category, add the appenders and set the default level -->
  <root level="debug">
    <appender-ref ref="FILE" />
  </root>

<!-- Specify the level specific to co.myapp.notifier -->
<logger name="co.myapp.notifier">
  <level value="ALL" />
  <appender-ref ref="virtuallab" />
</logger>

</configuration>

如果需要控制台日志,则可能还需要添加它。是文档,也请阅读此问题

Java 2022/1/1 18:16:54 有364人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶