GithubHelp home page GithubHelp logo

winter4666 / fastlog Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 16 KB

基于spring的aop特性,提供了一种通过注解打日志的方式,可以方便而且没有侵入性地记录程序运行过程中的各种重要日志

Java 100.00%
spring java aop log spel

fastlog's Introduction

fastlog

基于spring的aop特性,提供了一种通过注解打日志的方式,可以方便而且没有侵入性地记录程序运行过程中的各种重要日志

使用方法

  1. 修改spring配置,启用@AspectJ支持
<aop:aspectj-autoproxy/>
  1. 实现FastLogListener接口
public class OperLogRecorder implements FastLogListener {

	@Override
	public void log(String logType, List<LogField> logFields,Map<String, Object> contextMap) {
		StringBuilder logFieldsStr = new StringBuilder();
		for(LogField logField : logFields) {
			logFieldsStr.append(logField.getFieldName())
						.append(":")
						.append(logField.getFieldValue())
						.append(" ");
		}
		System.out.println("logType:" + logType + ",logFields:" + logFieldsStr + ",contextMap:" + contextMap);
	}
}
  1. FastLogAspect注入spring
<bean id="operLogRecorder" class="xxx.xxx.OperLogRecorder"/>
	
<bean class="com.github.winter4666.fastlog.FastLogAspect">
    <constructor-arg name="fastLogListener" ref="operLogRecorder"/>
</bean>
  1. 在需要记录日志的方法上面加上@FastLog注解,fieldValues里面填写的字符串为SpEL
@FastLog(value="userLogin",			
		fieldNames={"用户名","密码"},
		fieldValues={"#a0","#a1"})
public void login(String username, String password) {
	FastLogContext.put("测试", "任意值");
}
  1. 当上面注解的方法被调用时,FastLogListenerlog方法被回调,打印出下面的信息
logType:userLogin,logFields:用户名:test 密码:1234 ,contextMap:{测试=任意值}

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.