Springboot 日志配置

2023-11-27

我尝试配置我的 springboot 应用程序以登录一个文件一天,所以我配置我的 logback.xml 就像这样:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>

    <appender name="ROLLIN" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_FILE}</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

            <!-- daily rollover -->
            <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>

        </rollingPolicy>
    </appender>

    <root level="INFO">
        <appender-ref ref="ROLLIN" />
    </root>

    <logger name="org.springframework.web" level="INFO"/>
</configuration>

因此,当我尝试运行我的应用程序时,出现此错误:

Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[ROLLIN] - No encoder set for the appender named "ROLLIN".
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:151)
    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:71)
    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:49)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:106)
    at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:301)
    at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:253)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:225)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:201)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:119)
    at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:111)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:65)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:330)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
    at br.com.lumera.Application.main(Application.java:29)
:bootRun FAILED

正如例外所说,没有定义编码器。尝试类似的东西

  <appender name="ROLLIN" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logFile.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- daily rollover -->
      <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>

      <!-- keep 30 days' worth of history capped at 3GB total size -->
      <maxHistory>30</maxHistory>
      <totalSizeCap>3GB</totalSizeCap>

    </rollingPolicy>

    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
  </appender>

更多详情请见官方文档

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Springboot 日志配置 的相关文章

随机推荐

  • 5 张图像,用对角线对称分隔

    我浏览互联网并在 Reddit 上偶然发现了这个主题 看到这个可爱的横幅后 我想尝试使用我选择的五个对称图像来模拟类似的东西 这些图像由对角线分隔 就像上图一样 也许还可以尝试在各种图像上添加一些文字 像这样的东西 我尝试使用猫图片在 cs
  • 找不到查询模式的实现

    在我的 silverlight 应用程序中 我尝试使用 LINQ 创建数据库连接 首先 我添加一个新的 LINQ to SQL 类 并将名为 tblPerson 的表拖入其中 然后在我的服务文件中我尝试执行以下查询 OperationCon
  • 在 React 应用程序中加载初始服务器数据的逻辑应该放在哪里?

    我正在使用 React Redux 来构建一个应用程序 要加载 React 智能组件的初始数据 我需要调度一个Redux服务器数据请求将发生的操作 我尝试在构造函数 ES6 实现 中分派操作 componentWillMount and c
  • java.lang.IllegalArgumentException:不能有 viewTypeCount < 1

    我收到此错误 java lang IllegalArgumentException Can t have a viewTypeCount lt 1 我很确定我确切地知道是什么原因造成的 但我不知道如何解决它 我的应用程序从数据库加载用户朋友
  • FormHelper::label 和 FormTagHelper::label_tag 有什么区别?

    我正在编写一个处理多个模型的表单 有关如何执行此操作的一些示例ActionView Helpers FormHelper 标签 还有一些使用ActionView Helpers FormTagHelper label tag 我真的不明白其
  • 如何在 Xcode 中的模拟器构建中排除框架

    当我编译应用程序以在模拟器上运行时 如何从 Xcode 项目中排除仅为 iOS 设备架构编译的库 libssh2 等 我知道这是一个老问题 但如果有人仍在寻找答案 您可以使用弱链接指定某些库是optional See 这个答案是关于如何在
  • 如何使用jquery将整个html页面放入div中?

    首先 我想让大家知道我是一个绝对的初学者 所以请耐心等待 我想知道如何将整个 html 页面放入 div 中 我试过 footballPlayers html footballplayers html 但它显示footballplayers
  • 我究竟做错了什么? Java 非法格式转换异常

    我有一些计算圆属性的代码 package circleinfo import java util Scanner public class Circleinfo public static void main String args Sca
  • “hg revert”后我的更改消失了吗?

    在我上次提交之后 我写了一堆代码 在再次提交之前 我跑了hg add 它添加了一些我不感兴趣的文件 所以我跑了 hg revert all 认为所有添加的文件都会消失 它们确实消失了 但我还恢复了自上次提交以来编写的所有代码 这意味着大量工
  • 我是否必须将令牌存储在 cookie、本地存储或会话中?

    我正在使用 React SPA Express Express session Passport 和 JWT 我对存储令牌的一些不同客户端存储选项感到困惑 Cookie Session 和 JWT Passport 令牌是否必须存储在 co
  • 如何在Python中获取两个时间对象之间的差异

    我在 Python 中有两个 datetime time 对象 例如 gt gt gt x datetime time 9 30 30 0 gt gt gt y datetime time 9 30 31 100000 但是 当我对 dat
  • 在 com.google.android.gms.measurement.internal 解除绑定时抛出异常

    我收到此异常 但我不知道如何找到问题所在 也不知道是什么原因导致的 你能帮我吗 W ConnectionTracker Exception thrown while unbinding java lang IllegalArgumentEx
  • perl6 插入数组以匹配 AND、OR、NOT 函数

    我正在尝试重新执行我的程序 以匹配数组中的所有项目 匹配任意项目 不匹配项目 Perl6 的一些文档没有解释当前实现的行为 Rakudo 2018 04 我还有几个问题 1 正则表达式的文档说将数组插入匹配正则表达式意味着 最长匹配 但是
  • 如何让 IntelliJ IDEA 理解我的空检查方法?

    我有一个方法 其中参数标记为 Nonnull注解 调用该方法的代码必须检查该值是否为空 而不仅仅是直x null检查 它正在调用另一个类上的实用方法 在实际代码中 实用程序方法还会检查它是否为空字符串 我的问题是 Intellij Idea
  • 获取QTreeView中当前选定的项目

    我在 QTreeView 中有很多项目 每个项目都是使用此类生成的 class Branch QStandardItem def init self label uri None QStandardItem init self label
  • python 本地模块

    我有几个项目目录 并且想要特定于它们的库 模块 例如 我可能有这样的目录结构 myproject mymodules init py myfunctions py myreports mycode py 假设有一个函数叫做add in my
  • 如何使用 XmlPullParser 解析 RSS 提要?

    我想解析 RSS 提要 我的问题是如何解析之间的所有标签
  • Python中跨平台获取用户配置主目录的方法?

    我的程序需要存储一些配置文件 主要操作系统似乎都有一个指定的位置来放置它们 例如 在 Freedesktop org 兼容系统上 它将是存储在 XDG CONFIG HOME环境变量 是否有方法 或库 可以跨主要操作系统获取此配置主目录 W
  • 如何从 int 正确设置 UIColor?

    我正在尝试设置textColor of a UITextView通过给它赋值 在该计划的早期我有 textView textColor 0x000000 但后来 当我有 textView textColor 0x888888 弹出致命错误
  • Springboot 日志配置

    我尝试配置我的 springboot 应用程序以登录一个文件一天 所以我配置我的 logback xml 就像这样