• 请不要在回答技术问题时复制粘贴 AI 生成的内容
JasonLaw
V2EX  ›  程序员

想让 Spring Boot 的默认日志打印出文件名、方法名和行号,可以配置的吗?

  •  
  •   JasonLaw · Jun 9, 2021 · 3013 views
    This topic created in 1979 days ago, the information mentioned may be changed or developed.

    Spring Boot 的默认日志长下面这样,我想打印出文件名、方法名和行号,可以配置的吗?

    我不太想重写 pattern,现在使用的是CONSOLE_LOG_PATTERN。还是说只能重写 pattern 才能实现?

    14 replies  •  2021-06-10 14:15:41 +08:00
    coala
    coala
    Jun 9, 2021
    1
    logback
    coala
    coala
    Jun 9, 2021
    2
    文件名、方法名和行号 配置好 logback 就能满足
    limuyan44
    limuyan44
    Jun 9, 2021
    3
    logging.pattern.console= [%line:%file->%method] - %msg%n
    qwerthhusn
    qwerthhusn
    Jun 9, 2021
    4
    那样日志比较多的时候会严重影响性能
    JasonLaw
    JasonLaw
    OP
    Jun 9, 2021
    5
    @coala #2 你是说重写 pattern 吧?
    JasonLaw
    JasonLaw
    OP
    Jun 9, 2021
    6
    @qwerthhusn #4 为什么呢?
    realrojeralone
    realrojeralone
    Jun 9, 2021
    7
    @JasonLaw 获取行号或者文件名需要反射来实现
    BQsummer
    BQsummer
    Jun 9, 2021
    8
    我们公司把 info 级别的行号都去掉了,据说说是提高 20%的性能,不知道数据怎么来的,有没有大佬能提供更明确的数据结果
    knightdf
    knightdf
    Jun 9, 2021
    10
    @BQsummer 把 info 关掉估计能再提高 20%, = =
    karott7
    karott7
    Jun 9, 2021
    11
    请问楼主打印台字体颜色怎么弄的?
    MineDog
    MineDog
    Jun 10, 2021
    14
    获取行号之类一般是通过手动抛异常然后遍历堆栈拿的,所以会比较耗费性能
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2639 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 80ms · UTC 00:40 · PVG 08:40 · LAX 16:40 · JFK 19:40
    ♥ Do have faith in what you're doing.