简体   繁体   English

Logback 1.2.3 日志被中线截断

[英]Logback 1.2.3 logs being cut off mid-line

I am building a data crawler in Java.我正在 Java 中构建数据爬虫。 Here are some info:以下是一些信息:
Project: Gradle.项目:Gradle。
Framework: Vert.x 4.0.3.框架:Vert.x 4.0.3。
Logback version: 1.2.3.回溯版本:1.2.3。
slf4j version: 1.7.30. slf4j 版本:1.7.30。
Using Lombok使用龙目岛
MacBook Pro 15" mid 2014. MacBook Pro 15" 2014 年中。
Big Sur v 11.2.3.大苏尔 v 11.2.3。
Storage about 50% free.存储约 50% 免费。
Memory about 50% free in use. Memory 约 50% 免费使用。
Java version: Java 11. Java版本:Java 11.

My application is set so that HTTP GET requests are repeatedly called - ideally forever.我的应用程序设置为重复调用 HTTP GET 请求 - 理想情况下是永远。
And all the logs are logged to the terminal/console and also on the log file generated by logback.xml.并且所有日志都记录到终端/控制台以及 logback.xml 生成的日志文件中。
If I run my application overnight, then a log is cut off mid-line.如果我在一夜之间运行我的应用程序,那么一条日志会在中线被切断。
After the cut line, there is no log even though the terminal/console has all the logs.在剪切线之后,即使终端/控制台拥有所有日志,也没有日志。

Here is my logback.xml.这是我的 logback.xml。

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds" debug="true">

  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) %magenta(%-4relative) --- [ %thread{10} ] %cyan(%logger{20}) : %msg%n </pattern>
    </encoder>
  </appender>

  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--    <file>/var/log/crawler/crawler.log</file>-->
    <file>crawler.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--      <fileNamePattern>/var/log/crawler/crawler-%d{yyyy-MM-dd}.log</fileNamePattern>-->
      <fileNamePattern>crawler-%d.log</fileNamePattern>
      <maxHistory>30</maxHistory>
    </rollingPolicy>

    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %-4relative --- [ %thread{10} ] %logger{35} - %msg%n</pattern>
    </encoder>
  </appender>

  <logger name="io.netty" level="warn"/>
  <logger name="io.vertx" level="info"/>
  <logger name="com.hazelcast" level="info"/>
  <logger name="kr.co.evcloud.crawler" level="debug"/> <!-- 개발중에 편하게 쓰려고 변경하였습니다. -->

  <root level="debug">
    <appender-ref ref="CONSOLE"/> <!-- Console에 로그를 출력하고자 할 때 사용 -->
    <appender-ref ref="FILE"/> <!-- File로 로그를 남기고자 할 때 사용 -->
  </root>
</configuration>

The logback uses TimeBasedRollingPolicy , which on midnight, pushes all current logs to a new log file with the previous date. logback 使用TimeBasedRollingPolicy ,它在午夜将所有当前日志推送到具有前一个日期的新日志文件。

On two occasions, the following log was left.有两次留下以下日志。

2021-05-27 00:13:49.019 DEBUG 14038900 --- [ vert.x-eventloop-thread-1 ] k.c.e.crawler.service.MeDataService - ### [환경부 API] charger_id: 200949 새 상태: 2, 이전 상태: 9
2021-05-27 00:13:49.019 DEBUG 14038900 --- [ vert.x-eventloop-thread-1 ] k.c.e.crawler.service.MeDataService - ### [환경부 API] charger_id: 200958 새 상태: 2, 이전 상태: 9
2021-05-27 00:13:49.020 DEBUG 1403

There are three logs above: 2 of which are complete, one of which is cut off.上面有3个原木:2个完整,1个被截断。
And even though my terminal has all the logs since 00:13:49 til now, the log file is not being updated.即使我的终端拥有从 00:13:49 到现在的所有日志,日志文件也没有被更新。

Any guesses as to why this happens?关于为什么会发生这种情况的任何猜测?

Thanks in advance.提前致谢。

I found the problem.我发现了问题。
I am using IntelliJ IDEA.我正在使用 IntelliJ IDEA。

IntelliJ IDEA 2021.1.1 (Community Edition)
Build #IC-211.7142.45, built on April 30, 2021
Runtime version: 11.0.10+9-b1341.41 x86_64

When I opened the log files with cut lines in VSCode, all the logs showed.当我在 VSCode 中打开带有剪切线的日志文件时,所有日志都显示出来了。
IntelliJ seems show only part of large.log files. IntelliJ 似乎只显示 large.log 文件的一部分。

If anyone stumbles on not seeing your logs or cut off lines of logs, try opening the file in different IDE or program.如果有人偶然发现看不到您的日志或切断日志行,请尝试在不同的 IDE 或程序中打开文件。

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

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