简体   繁体   English

使用 Logback 的日志中不可读的线程名称

[英]Unreadable thread name in logs with Logback

I run Spring Boot application and have following logback-spring.xml file:我运行 Spring 引导应用程序并具有以下logback-spring.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <property name="LOGS" value="./logs" />

    <appender name="Console"
              class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>
                %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
            </Pattern>
        </layout>
    </appender>

    <appender name="RollingFile"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOGS}/logger.log</file>
        <encoder
                class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <charset>UTF-8</charset>
            <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
        </encoder>

        <rollingPolicy
                class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover daily and when the file reaches 10 MegaBytes -->
            <fileNamePattern>${LOGS}/archived/logger-%d{yyyy-MM-dd}.%i.log
            </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>

    <!-- LOG everything at INFO level -->
    <root level="info">
        <appender-ref ref="RollingFile" />
        <appender-ref ref="Console" />
    </root>
</configuration>

Default Spring Boot logs works fine:默认 Spring 引导日志工作正常:

2020-07-06 10:24:02,276 INFO  [restartedMain] org.springframework.boot.SpringApplication: No active profile set, falling back to default profiles: default

But when app tries to log incoming information, I'll get:但是当应用程序尝试记录传入信息时,我会得到:

2020-07-06 10:24:24,604 INFO  [Áèáëèîòåêà èãð Google Play Telegram Executor] ru.miroha.bot.GooglePlayGameBot: Hello, Test!

Same in the console and a file.在控制台和文件中相同。

Google Play Telegram Executor is legit, but what is Áèáëèîòåêà èãð it? Google Play Telegram Executor是合法的,但Áèáëèîòåêà èãð是什么?

If I'll remove this logback.xml configuration and run with default Spring Bot logger this message will look like:如果我将删除此 logback.xml 配置并使用默认 Spring Bot 记录器运行,则此消息将如下所示:

2020-07-06 10:22:00.418  INFO 6796 --- [legram Executor] ru.miroha.bot.GooglePlayGameBot          : Hello!

What's wrong?怎么了?

The encoded text is coming from %C{1.} in your config.编码文本来自配置中的%C{1.} Maybe the caller of your object has classnames intentionally obfuscated?也许您的 object 的调用者故意混淆了类名? Is the class invoking that row from a library? class 是否从库中调用该行?

Do you need that depth of caller loging?caller that you want to be logging as opposed to %C{0} ?您是否需要调用者记录的深度?您想要记录的调用者而不是%C{0}

More on caller logging: http://logback.qos.ch/manual/layouts.html有关来电记录的更多信息: http://logback.qos.ch/manual/layouts.html

I found the real problem.我发现了真正的问题。 This thread name contains my telegram bot name (api features I guess), and this api cannot correctly process the cyrillic alphabet.此线程名称包含我的电报机器人名称(我猜是 api 功能),并且此 api 无法正确处理西里尔字母。

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

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