IntelliJ IDEA 控制台颜色消失问题及解决方案

IntelliJ IDEA 控制台颜色消失问题及解决方案

问题描述

Log4j 2 在 IntelliJ IDEA 控制台可能导致日志颜色丢失,原因包括:

  1. 默认未启用 ANSI 颜色支持。
  2. IDEA 未开启 ANSI 解析。
  3. 缺少 Jansi 库(Windows)。
  4. 依赖冲突。

解决方案

  1. 启用颜色支持

    xml 复制代码
    <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %highlight{%-5p}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=blue, TRACE=cyan} %c{1}:%L - %m%n"/>
  2. 添加 Jansi 依赖(Windows)

    xml 复制代码
    <dependency>
        <groupId>org.fusesource.jansi</groupId>
        <artifactId>jansi</artifactId>
        <version>2.4.0</version>
    </dependency>
  3. 启用 IDEA ANSI 支持

    • File > Settings > Editor > Console Colors,勾选 Use console ANSI colors.
  4. 检查依赖冲突

    • 使用 mvn dependency:tree 排除 Log4j 1.x 或其他框架冲突。
  5. 设置系统属性

    • Log4j2 JVM 参数:-Dlog4j2.enableJansi=true

    • Log4j JVM 参数: -Dlog4j.skipJansi=false

  6. 验证

    • 检查颜色输出,启用 status="debug" 排查问题。

使用插件

Grep Console Plugin for JetBrains IDEs | JetBrains Marketplace

相关推荐
viaco2love1 天前
开源的intellij ide 的claude code 插件和codex 插件
intellij idea·claude code·codex 插件
云灬沙2 天前
IDEA2025无法更新使用Terminal控制台
java·intellij-idea·idea·intellij idea
那我掉的头发算什么8 天前
【数据结构】二叉树的高频热门面试题大全
java·开发语言·数据结构·python·算法·链表·intellij idea
minh_coo16 天前
Spring框架接口之RequestBodyAdvice和ResponseBodyAdvice
java·后端·spring·intellij idea
舒一笑17 天前
PandaCoder 1.1.8 发布:中文开发者的智能编码助手全面升级
java·后端·intellij idea
卷Java18 天前
百度智能云车牌识别API官方配置指南
java·开发语言·经验分享·vscode·学习·微信小程序·intellij idea
皮皮林55124 天前
IDEA 源码阅读利器,你居然还不会?
java·intellij idea
再见晴天*_*1 个月前
SpringBoot 中单独一个类中运行main方法报错:找不到或无法加载主类
java·开发语言·intellij idea
十八旬1 个月前
【超简单】后端入门案例-基于SpringBoot+MyBatis-plus+MySQL图书管理系统
java·开发语言·idea·intellij idea·项目实战
韦禾水1 个月前
IntelliJ IDEA 2023更新git凭据
git·intellij idea