演示日志模块的使用
- 操作日志
在需要记录操作日志的方法上添加注解,例子:
@OperateLog("操作日志内容")
- 自定义日志
例子:
@Autowired
private MagicLogger magicLogger;
magicLogger.warn("日志前缀", "日志内容");
magicLogger.debug("日志前缀", "日志内容");
magicLogger.info("日志前缀", "日志内容");
magicLogger.error("日志前缀", "日志内容");
- 错误日志
建议在全局拦截的地方触发,例子:
LogEventPublisher.publishErrorLogEvent(exception);
- 继承 LogHandler 重写对应日志类型处理方法即可,例子:https://github.com/xkcoding/magic-starter-log-demo/blob/master/src/main/java/com/xkcoding/magicstarterlogdemo/config/support/DemoLogHandler.java
- 交给 Spring 容器管理,例子:https://github.com/xkcoding/magic-starter-log-demo/blob/master/src/main/java/com/xkcoding/magicstarterlogdemo/config/LogConfig.java
/**
* <p>
* 日志执行逻辑
* </p>
*
* @author yangkai.shen
* @date Created in 2019/9/24 19:43
*/
@Slf4j
public class DemoLogHandler implements LogHandler {
@Override
public void handleOperateLog(OperateLogModel logModel) {
log.info("【OperateLogModel】= {}", JSONUtil.toJsonStr(logModel));
}
@Override
public void handleCustomLog(CustomLogModel logModel) {
log.info("【CustomLogModel】= {}", JSONUtil.toJsonStr(logModel));
}
@Override
public void handleErrorLog(ErrorLogModel logModel) {
log.info("【ErrorLogModel】= {}", JSONUtil.toJsonStr(logModel));
}
}
magic:
log:
request:
enabled: true
spring:
application:
name: magic-starter-log-demo
logging:
config: classpath:com/xkcoding/magic/log/logback/logback-spring.xml