同事在全部controller方法里加入了輸入參數的log輸出,輸出數據的log輸出或者使用aop的方式。真的很煩,鳥菜啊給你們一個簡單的方式。html
@Slf4j @RestController public class UserController{ @RequestMapping("getUserInfo") public UserInfo getUserInfo(Long userId ){ log.info("------------->查詢getUserInfo入參{}", id); xxxxxxxx log.info("------------->查詢getUserInfo輸出{}", xxx); } @RequestMapping("newGetUserInfo") public UserInfo getUserInfo(Long userId , Long appId){ log.info("------------->查詢getUserInfo入參id: {} , appId:{}", id, appId); xxxxxxxx log.info("------------->查詢getUserInfo輸出{}", xxxx); } }
工做量大,代碼不優雅(難看死了),日誌信息與配置容易出錯,配置很差管理java
百度一下隨便找一個spring aop實現日誌輸出的,麻煩你們點擊下Spring AOP實現統一日誌輸出。是在不想萬惡的重複造輪子程序員
管理很是麻煩,容易出錯,須要必定功底的程序員維護,成本大,代價大。web
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-access</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> </dependency>
<logger name="org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod" level="trace" />
2019-10-21 12:02:18.640 [http-nio-12140-exec-2] TRACEo.s.w.s.m.m.a.ServletInvocableHandlerMethod - Invoking 'com.xxx.UserController.getUserInfo' with arguments [1] 2019-10-21 12:02:18.920 [http-nio-12140-exec-2] TRACEo.s.w.s.m.m.a.ServletInvocableHandlerMethod - Method [com.xxx.UserController.getUserInfo] returned [xxxx]