All Projects → dadiyang → Autologging

dadiyang / Autologging

Licence: apache-2.0
一个非常强大的监控日志输出框架,支持 SpringAOP 和动态字节码注入两种方式输出方法执行的监控日志,而且包含链路追踪功能,只要一个注解即可开启所有功能

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Autologging

Logdna Agent
LogDNA Agent streams from log files to your LogDNA account. Works with Linux, Windows, and macOS Servers
Stars: ✭ 134 (+139.29%)
Mutual labels:  logging, monitor
Frostmourne
frostmourne是基于Elasticsearch, InfluxDB数据,Mysql数据的监控,报警,分析系统. Monitor & alert & alarm & analyze for Elasticsearch && InfluxDB Log Data。主要使用springboot2 + vue-element-admin。 https://frostmourne-demo.github.io/
Stars: ✭ 166 (+196.43%)
Mutual labels:  logging, monitor
Zentral
Zentral is an open-source solution for infrastructure monitoring and endpoint event stream processing. It provides build-in orchestration of macOS security components (Santa, Osquery, et-al.), event correlation and event management. It consolidates its features with various data store backends (ElasticStack, Azure Log Analytics, Splunk, et-al.).
Stars: ✭ 522 (+832.14%)
Mutual labels:  logging, monitor
Tron
R package for easy logging
Stars: ✭ 38 (-32.14%)
Mutual labels:  logging
Log4j2 Ttl Thread Context Map
🌳 Log4j2 TTL ThreadContextMap, Log4j2 extension integrated TransmittableThreadLocal to MDC
Stars: ✭ 41 (-26.79%)
Mutual labels:  logging
Serverless Es Logs
A Serverless plugin to transport logs to ElasticSearch
Stars: ✭ 51 (-8.93%)
Mutual labels:  logging
Aspnetcorenlog
ASP.NET Core NLog MS SQL Server PostgreSQL MySQL Elasticsearch
Stars: ✭ 54 (-3.57%)
Mutual labels:  logging
Spring Boot
spring-boot 项目实践总结
Stars: ✭ 989 (+1666.07%)
Mutual labels:  aop
Raspberrypi tempmon
Raspberry pi CPU temperature monitor with many functions such as logging, GPIO output, graphing, email, alarm, notifications and stress testing. Python 3.
Stars: ✭ 52 (-7.14%)
Mutual labels:  logging
Log4cplus
log4cplus is a simple to use C++ logging API providing thread-safe, flexible, and arbitrarily granular control over log management and configuration. It is modelled after the Java log4j API.
Stars: ✭ 1,054 (+1782.14%)
Mutual labels:  logging
Qtwebapp
QtWebApp is a HTTP server like Java servlets, written in C++ with the Qt framework.
Stars: ✭ 50 (-10.71%)
Mutual labels:  logging
Log
Logging implementation for Rust
Stars: ✭ 1,012 (+1707.14%)
Mutual labels:  logging
Plog
Portable, simple and extensible C++ logging library
Stars: ✭ 1,061 (+1794.64%)
Mutual labels:  logging
Fliplog
fluent logging with verbose insight, colors, tables, emoji, filtering, spinners, progress bars, timestamps, capturing, stack traces, tracking, presets, & more...
Stars: ✭ 41 (-26.79%)
Mutual labels:  logging
Nlogger
Logging lib for Node.js that prints also module name and line number
Stars: ✭ 52 (-7.14%)
Mutual labels:  logging
Nitro
Stars: ✭ 38 (-32.14%)
Mutual labels:  monitor
Multithreading
C#多线程编程实战
Stars: ✭ 52 (-7.14%)
Mutual labels:  monitor
Rssa
RSS-Anything, get updates about anything you can reach with an url. Like RSS, but for anything.
Stars: ✭ 46 (-17.86%)
Mutual labels:  monitor
Browser Logger
A dead simple logger, designed to be perfect for the browser.
Stars: ✭ 44 (-21.43%)
Mutual labels:  logging
Burrowx
Kafka consumer lag monitor
Stars: ✭ 50 (-10.71%)
Mutual labels:  monitor

AutoLogging 监控日志框架

一个非常强大的监控日志输出框架,主要功能包含

  • 方法监控日志输出
  • 应用内调用链路追踪

可以通过

  • SpringAOP
  • 动态字节码运行时注入

两种方式引入,只要一个注解即可开启所有功能,而且具有强大的可扩展性

背景

在开发过程中,我们常常会看到这样的代码:

@GetMapping("{id}")
public ReturnDTO<User> getById(int id) {
    log.info("根据主键id查询用户, id: {}", id);
    long startTime = System.currentTimeMillis();
    try {
        ReturnDTO<User> rs =  ResultUtil.successResult(userService.getById(id));
        log.debug("根据主键id查询用户成功, id: {}, 耗时: {}", id, (System.currentTimeMills() - startTime));
        return rs;
    } catch (Exception e) {
        log.error("据主键id查询用户发生异常, id: {}, 耗时: {}", id, (System.currentTimeMills() - startTime), e);
        return ResultUtil.errorResult("据主键id查询用户发生异常, id: " + id);
    }
}

这种写法有以下几个问题:

  • 代码冗余,不易维护
  • 日志格式不统一,难以自动化分析
  • 容易遗漏或者写错日志信息,问题排查艰难

这些问题都给开发、测试和线上排查问题造成困扰

想象一下,整个项目当中,我们有多少个像这样的方法?DRY!

特点

只需要添加 maven 依赖,然后给全局打上一个注解,就能开启所有功能,我们就可以去掉所有监控日志,由框架统一输出:

@GetMapping("{id}")
public ReturnDTO<User> getById(int id) {
    return ResultUtil.successResult(userService.getById(id));
}

自动日志框架会自动输出方法的监控日志

效果展示

2020-03-01 13:38:46.483  INFO 54635 --- [           main] c.g.d.a.c.l.LocalLogTraceListener        : 121361440260956160 | 2 | Repository |  | com.github.dadiyang.autologging.test.user.UserMapperFakeImpl | getById | [830293] | {"id":830293,"username":"张三"} | 4
2020-03-01 13:38:46.484  INFO 54635 --- [           main] c.g.d.a.c.l.LocalLogTraceListener        : 121361440260956160 | 1 | Service |  | com.github.dadiyang.autologging.test.user.UserServiceImpl | getById | [830293] | {"id":830293,"username":"张三"} | 27
2020-03-01 13:38:46.485  INFO 54635 --- [           main] c.g.d.a.c.l.LocalLogTraceListener        : 121361440260956160 | 0 | Controller | GET 127.0.0.1 http://localhost/user/getById   | com.github.dadiyang.autologging.test.user.UserController | getById | [830293] | {"id":830293,"username":"张三"} | 39
2020-03-01 13:38:46.528 ERROR 54635 --- [           main] c.g.d.a.c.l.LocalLogTraceListener        : 121361440592306176 | 2 | Repository | | com.github.dadiyang.autologging.test.user.UserMapperFakeImpl | updateById | [{"id":830293,"username":"张三"}] | 0 | java.lang.UnsupportedOperationException: 模拟抛出异常
	at com.github.dadiyang.autologging.test.user.UserMapperFakeImpl.updateById(UserMapperFakeImpl.java:14)
	at com.github.dadiyang.autologging.test.user.UserMapperFakeImpl$$FastClassBySpringCGLIB$$8b95b1d3.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)

项目结构

本框架分为 core、aop、aop-jvm-sandbox、test 四个项目,其中

  • core 核心模块,包含配置和上报相关的日志监听器的定义;
  • aop 通过 SpringAOP 打印和上报方法执行的监控信息,包括对 Controller、 Service 和 Mapper 层的监控日志,以及统一异常处理;
  • aop-jvm-sandbox 基于 jvm-sandbox 框架实现的无侵入的 AOP 日志实现,它提供了一个能力,让应用完全无感的情况下,在运行时动态将监控日志相关代码织入到目标应用中,使之拥有输入监控日志的能力
  • test 用于测试

快速开始

基于 aop 的方法级监控日志

以 SpringBoot 环境使用为例

maven 依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
    <groupId>com.github.dadiyang</groupId>
    <artifactId>autologging-aop</artifactId>
    <version>1.0.0</version>
</dependency>

注解

在 Application 类上添加 @EnableServiceLog 注解开启 Service 层的监控

各个切面有预置的注解,可以根据需要挑选添加:

注解 释义 备注
@EnableMarkLog 启用所有带 @MarkLog 注解的类和方法 在需要监控的类或方法上添加 @MarkLog
@AutoLogAll 开启所有切面的日志监控功能,打印到本地,如果有引入 Kafka 相关配置则进行上报
@AutoLogAllLocal 开启所有切面的日志监控功能,打印到本地
@EnableControllerLog 开启 Controller 日志
@EnableServiceLog 开启 Service 的日志 带有 @Service 的类
@EnableMapperLog 开启 Mapper 层的日志 带有 @Mapper 的类
@RepositoryLogAspect 开启 Repository 的日志 带有 @Repository 的类

配置

autolog:
    # 请填写应用名称,必填!
    app-name: 

OK,搞定!启动之后应用中的各个切面方法执行的时候就会打印相关的日志了。

更多配置项请查看:autologging-aop

交个朋友

donation

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].