Coder Social home page Coder Social logo

easy-log's Introduction

EasyLog

基于SpringAOP实现的日志打印工具。

引入项目

<dependency>
    <groupId>com.github.hanselma</groupId>
    <artifactId>easy-log</artifactId>
    <version>1.0.0</version>
</dependency>

自定义收集器

通过集成LogRecorder来实现自己的收集器:

@Component
public class MyRecorder implements LogRecorder {
    private final ObjectMapper objectMapper = new ObjectMapper();
    private static final Logger logger = LoggerFactory.getLogger(SLF4JLogger.class);

    @Override
    public void record(RecordData logData) {
        try {
            logger.info(objectMapper.writeValueAsString(logData));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }
}

通过注解埋点收集

@RestController
public class MyController {

    @EasyLog(operationType = "测试", stackTraceOnErr = true, recorder = MyRecorder.class)
    @GetMapping("/app/sayHello")
    public String sayHello() {
        EasyLogData.step("1. 第一步执行完成");
        EasyLogData.step("2. 第二步执行完成");
        EasyLogData.step("3. service的方法执行完成");
        return "hello";
    }
}

注解参数

选项 类型 说明 默认
operationType String 本次记录的类型 undefined
recordOnError boolean 仅当发生异常时才收集 false
stackTraceOnErr boolean 当目标方法发生异常时,是否追加异常堆栈信息到LogData的content中 false
asyncMode boolean 异步方式收集 true
recorder Class<? extends LogRecorder> 指定日志收集器 默认不调整收集器,使用全局的日志收集器

easy-log's People

Contributors

mahongsheng avatar

Stargazers

Gavin avatar Eric avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.