V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
JasonLaw
V2EX  ›  程序员

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

  •  
  •   JasonLaw · 2021-06-09 11:59:49 +08:00 · 2058 次点击
    这是一个创建于 1044 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    14 条回复    2021-06-10 14:15:41 +08:00
    coala
        1
    coala  
       2021-06-09 13:08:12 +08:00
    logback
    coala
        2
    coala  
       2021-06-09 13:09:27 +08:00
    文件名、方法名和行号 配置好 logback 就能满足
    limuyan44
        3
    limuyan44  
       2021-06-09 13:11:27 +08:00
    logging.pattern.console= [%line:%file->%method] - %msg%n
    qwerthhusn
        4
    qwerthhusn  
       2021-06-09 13:37:45 +08:00
    那样日志比较多的时候会严重影响性能
    JasonLaw
        5
    JasonLaw  
    OP
       2021-06-09 14:01:56 +08:00
    @coala #2 你是说重写 pattern 吧?
    JasonLaw
        6
    JasonLaw  
    OP
       2021-06-09 14:26:34 +08:00
    @qwerthhusn #4 为什么呢?
    realrojeralone
        7
    realrojeralone  
       2021-06-09 14:36:38 +08:00
    @JasonLaw 获取行号或者文件名需要反射来实现
    BQsummer
        8
    BQsummer  
       2021-06-09 14:50:51 +08:00
    我们公司把 info 级别的行号都去掉了,据说说是提高 20%的性能,不知道数据怎么来的,有没有大佬能提供更明确的数据结果
    qwerthhusn
        9
    qwerthhusn  
       2021-06-09 15:40:18 +08:00
    knightdf
        10
    knightdf  
       2021-06-09 16:52:59 +08:00
    @BQsummer 把 info 关掉估计能再提高 20%, = =
    karott7
        11
    karott7  
       2021-06-09 21:49:52 +08:00
    请问楼主打印台字体颜色怎么弄的?
    MineDog
        14
    MineDog  
       2021-06-10 14:15:41 +08:00
    获取行号之类一般是通过手动抛异常然后遍历堆栈拿的,所以会比较耗费性能
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3689 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 00:50 · PVG 08:50 · LAX 17:50 · JFK 20:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.