通过Arthas来动态打印日志

栏目: 数据库 · 发布时间: 6年前

内容简介:需求线上一个Spring boot应用 通过MyBatis来操作数据库 定位一个线上问题 想动态打印sql日志解决

需求

线上一个Spring boot应用 通过MyBatis来操作数据库 定位一个线上问题 想动态打印 sql 日志

解决

通过 Arthas工具 来实现上述的需求

$ ognl '@org.slf4j.LoggerFactory@getLogger("com.foo.cpts.mapper")'
@Logger[
    serialVersionUID=@Long[5454405123156820674],
    FQCN=@String[ch.qos.logback.classic.Logger],
    name=@String[com.foo.cpts.mapper],
    level=null,
    effectiveLevelInt=@Integer[20000],
    parent=@Logger[Logger[com.foo.cpts]],
    childrenList=@CopyOnWriteArrayList[isEmpty=false;size=2],
    aai=null,
    additive=@Boolean[true],
    loggerContext=@LoggerContext[ch.qos.logback.classic.LoggerContext[default]],
]

刚开始Mapper包对应的日志级别是null 将其改成DEBUG

$ ognl '@org.slf4j.LoggerFactory@getLogger("com.foo.cpts.mapper").setLevel(@ch.qos.logback.classic.Level@DEBUG)'
null

$ ognl '@org.slf4j.LoggerFactory@getLogger("com.foo.cpts.mapper")'
@Logger[
    serialVersionUID=@Long[5454405123156820674],
    FQCN=@String[ch.qos.logback.classic.Logger],
    name=@String[com.foo.cpts.mapper],
    level=@Level[DEBUG],
    effectiveLevelInt=@Integer[10000],
    parent=@Logger[Logger[com.foo.cpts]],
    childrenList=@CopyOnWriteArrayList[isEmpty=false;size=2],
    aai=null,
    additive=@Boolean[true],
    loggerContext=@LoggerContext[ch.qos.logback.classic.LoggerContext[default]],
]

此时当调用Mapper方法时 能打印出sql日志了 同样关闭sql日志 改成info即可

$ ognl '@org.slf4j.LoggerFactory@getLogger("com.foo.cpts.mapper").setLevel(@ch.qos.logback.classic.Level@INFO)'
null

补充

因为打印sql日志对应的配置是

logging.level.com.foo.cpts.mapper=DEBUG

刚开始想着通过下面的方式来实现

ognl '@java.lang.System@setProperty("logging.level.com.foo.cpts.mapper","DEBUG")'

但是该方式并未起作用


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

微商团队管理实战手册

微商团队管理实战手册

杜一凡 / 人民邮电出版社 / 2015-11 / 45.00元

回顾淘宝,用了10年时间才发展了不到1000万的卖家,再看微商,其仅一年时间就拥有了超过1000万的卖家。进入2015年,微商的发展之路虽有小坎坷,但前景依然被看好。然而任何一个想要做大、做强的微商都要以团队形式来发展,独立的个体只会举步维艰。 本书全面解读微商团队管理的营销书。全书共分为六章,分别从微商团队的商业秘密、微商团队的战略布局、管理基本功、建立高效团队、精通管理工具、未来发展等方......一起来看看 《微商团队管理实战手册》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具