本文介绍一种SpingBoot系统操作记录的实现方法,主要解决谁在什么时间对什么做了什么事。
10余年的青山网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整青山建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“青山网站设计”,“青山网站推广”以来,每个客户项目都认真落实执行。
io.github.mouzt
bizlog-sdk
3.0.0
@EnableLogRecord(tenant = "com.zhangls.log")
@SpringBootApplication
public class LogApplication {
public static void main(String[] args) {
SpringApplication.run(LogApplication.class, args);
}
}
@LogRecord(
subType = "开发文章浏览",
extra = "{{#browseRecord.toString()}}",
success = "{{#browseRecord.username}}查看了「{{#browseRecord.articleTitle}}」,结果:{{#_ret}}",
type = "scan",
bizNo = "{{#browseRecord.articleId}}")
public boolean success(BrowseRecord browseRecord) {
return true;
}
【logRecord】log=LogRecord(id=null, tenant=com.zhangls.log, type=scan, subType=开发文章浏览, bizNo=9999, operator=111, actinotallow=九天银河聊编程查看了「JAVA技术揭秘」,结果:true, fail=false, createTime=Mon Mar 06 10:41:25 CST 2023, extra=BrowseRecord(username=九天银河聊编程, articleId=9999, articleTitle=JAVA技术揭秘), codeVariable={ClassName=interface
com.zhangls.log.service.LogService, MethodName=success})
@LogRecord(
fail = "浏览失败,失败原因:「{{#_errorMsg}}」",
subType = "开发文章浏览",
extra = "{{#browseRecord.toString()}}",
success = "{{#browseRecord.username}}查看了「{{#browseRecord.articleTitle}}」,结果:{{#_ret}}",
type = "scan",
bizNo = "{{#browseRecord.articleId}}")
public boolean fail(BrowseRecord browseRecord) {
int tmp = 1 / 0;
return false;
}
【logRecord】log=LogRecord(id=null, tenant=com.zhangls.log, type=scan, subType=开发文章浏览, bizNo=9999, operator=111, actinotallow=浏览失败,失败原因:「/ by zero」, fail=true, createTime=Mon Mar 06 10:48:34 CST 2023, extra=BrowseRecord(username=九天银河聊编程, articleId=9999, articleTitle=JAVA技术揭秘), codeVariable={ClassName=interface
com.zhangls.log.service.LogService, MethodName=fail})
当然也有一个报错信息:
@Component("diff")
public class DiffParseFunction implements IParseFunction {
@Override
public boolean executeBefore() {
return true;
}//设置在执行前记录
@Override
public String functionName() {
return "DIFF";
}
@Override
public String apply(Object value) {
if (StringUtils.isEmpty(value)) {
return "";
}
return "".concat("(").concat(value.toString()).concat(")");
}
}
@Override
@LogRecord(success = "更新前{DIFF{#browseRecord}},更新后{{#browseRecord}}",
type = "scan",
bizNo = "{{#browseRecord.articleId}}")
public boolean diff(BrowseRecord browseRecord) {
browseRecord.setArticleTitle("C#技术揭秘");
return true;
}
【logRecord】log=LogRecord(id=null, tenant=com.zhangls.log, type=scan, subType=, bizNo=9999, operator=111, actinotallow=更新前(BrowseRecord(username=九天银河聊编程, articleId=9999, articleTitle=JAVA技术揭秘)),更新后BrowseRecord(username=九天银河聊编程, articleId=9999, articleTitle=C#技术揭秘), fail=false, createTime=Mon Mar 06 10:55:14 CST 2023, extra=, codeVariable={ClassName=interface
com.zhangls.log.service.LogService, MethodName=diff})
根据com.mzt.logapi.beans.LogRecord创建数据库表结构,生成实体、mapper、XML文件,此过程略。
编写日志保存服务类。
@Service
public class LogRecordServiceImpl implements ILogRecordService {
@Resource
private TLogrecordMapper logRecordMapper;
@Override
public void record(LogRecord logRecord) {
TLogrecord record = new TLogrecord();
BeanUtils.copyProperties(logRecord, record);
logRecordMapper.insert(record);
}
@Override
public ListqueryLog(String bizNo, String type) {
return null;
}
@Override
public ListqueryLogByBizNo(String bizNo, String type, String subType) {
return null;
}
}
@Override
@LogRecord(
fail = "失败原因:「{{#_errorMsg}}」",
subType = "开发文章浏览",
operator = "admin",
extra = "{{#browseRecord.toString()}}",
success = "{{#browseRecord.username}}查看了「{{#browseRecord.articleTitle}}」,结果:{{#_ret}}",
type = "scan",
bizNo = "{{#browseRecord.articleId}}")
public boolean saveDb(BrowseRecord browseRecord) {
return true;
}
当前文章:SpringBoot中通过注解优雅记录操作日志
文章路径:http://www.mswzjz.cn/qtweb/news10/527510.html
攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能