All Projects → controller-logger → controller-logger

controller-logger / controller-logger

Licence: Apache-2.0 license
AOP based API logging for Spring Boot

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to controller-logger

Swoft
🚀 PHP Microservice Full Coroutine Framework
Stars: ✭ 5,420 (+9408.77%)
Mutual labels:  annotations, aop
AspecTS
An aspect-oriented programming library implemented in TypeScript
Stars: ✭ 21 (-63.16%)
Mutual labels:  aop, aspects
Ray.di
Guice style dependency injection framework for PHP
Stars: ✭ 175 (+207.02%)
Mutual labels:  annotations, aop
aspecio
Aspecio, AOP Proxies for OSGi services
Stars: ✭ 14 (-75.44%)
Mutual labels:  annotations, aspects
Jcabi Aspects
Collection of AOP/AspectJ Java Aspects
Stars: ✭ 455 (+698.25%)
Mutual labels:  annotations, aop
Hyperf
🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.
Stars: ✭ 4,206 (+7278.95%)
Mutual labels:  annotations, aop
Aspect4Delphi
Concepts of aspect-oriented programming (AOP) in Delphi.
Stars: ✭ 28 (-50.88%)
Mutual labels:  aop, aspects
S Mall Ssm
小小商城系统,JavaWEB项目,基于SSM,仿天猫页面,功能齐全,实现了自动处理关联查询的通用Mapper、抽象 BaseService 类、注解鉴权、参数注解校验等
Stars: ✭ 456 (+700%)
Mutual labels:  annotations, aop
Laravel Aspect
aspect oriented programming Package for laravel framework
Stars: ✭ 98 (+71.93%)
Mutual labels:  annotations, aop
Drf Typed Views
Use type annotations to validate/deserialize request parameters in Dango REST Framework.
Stars: ✭ 181 (+217.54%)
Mutual labels:  annotations
Koro1fileheader
VSCode插件:自动生成,自动更新VSCode文件头部注释, 自动生成函数注释并支持提取函数参数,支持所有主流语言,文档齐全,使用简单,配置灵活方便,持续维护多年。
Stars: ✭ 3,137 (+5403.51%)
Mutual labels:  annotations
Placeholderview
This library provides advance views for lists and stacks. Some of the views are build on top of RecyclerView and others are written in their own. Annotations are compiled by annotation processor to generate bind classes. DOCS -->
Stars: ✭ 2,104 (+3591.23%)
Mutual labels:  annotations
Oksharedprefs
通过注解生成SharedPreferences包装类,解决跨进程数据访问不同步的问题。
Stars: ✭ 183 (+221.05%)
Mutual labels:  annotations
React Tater
A React component to add annotations to any element on a page 🥔
Stars: ✭ 235 (+312.28%)
Mutual labels:  annotations
Cocostuff10k
The official homepage of the (outdated) COCO-Stuff 10K dataset.
Stars: ✭ 248 (+335.09%)
Mutual labels:  annotations
Sequelize Typescript
Decorators and some other features for sequelize
Stars: ✭ 2,200 (+3759.65%)
Mutual labels:  annotations
Beanutils
BeanUtils library is a Java bean copy utility with powerful functionality and high performance.
Stars: ✭ 164 (+187.72%)
Mutual labels:  annotations
stylelint-problem-matcher
A GitHub Action that registers a problem matcher for Stylelint's report format
Stars: ✭ 18 (-68.42%)
Mutual labels:  annotations
Annotation tools
Visipedia Annotation Tools
Stars: ✭ 245 (+329.82%)
Mutual labels:  annotations
Labelimg
🖍️ LabelImg is a graphical image annotation tool and label object bounding boxes in images
Stars: ✭ 16,088 (+28124.56%)
Mutual labels:  annotations

Controller Logger

Discord CircleCI codecov FOSSA Status

Buy Me a Coffee

Upcoming release features

  1. Performance improvements
  2. Dependency updates

What is it?

A Java library to ease the life of web developers by providing automatic logging of input-output for controllers. Logged items include all parameters, returned value and some context data such as web request URL and user's username.

Features

  1. Automatically logs all APIs including input and output.
  2. Automatically logs errors occurring in API.
  3. No side-effect in actual API implementation due to AOP logic.
  4. Automatically binds to new APIs thanks to AOP weaving.
  5. Scrubs sensitive information in logs to maintain security and privacy.
  6. Displays file size if one of the API input or output is any file object.
  7. Works with integration testing.
  8. Detects mocked objects in input and output and displays them accordingly, as can happen during integration testing.
  9. Logging behaviour is easily customizable.

Performance

The code has been through multiple profiling cycles. Each part of the code is intended for maximum performance. No object it serialized if it didn't need to.

Why does it exist?

While working on a project, a Spring-based web application, it quickly became annoying adding the same log statements for each new controller method being created. Working in a team made it inconsistent too with people forgetting or adding unformatted logs. This was the perfect use case for AOP (Aspect Oriented Programming). This library is re-built based on experience gained during my original implementation of AOP based logging.

How can I use this awesome library?

Requirements -

  • Java 8
  • Spring Boot

Through requirements specify Spring Boot, you will be able to use it with classic Spring Framework as well but you'll have to implement weaving manually. This StackOverflow question of mine will be helpful in doing so.

Usage

Example usage of this library can be found here - https://github.com/harshilsharma63/controller-logger-example

Setup

  1. Add dependency from http://www.mvnrepository.com/artifact/io.github.harshilsharma63/controller-logger
  • Gradle

    compile group: 'io.github.harshilsharma63', name: 'controller-logger', version: '1.2.0'
    
  • Maven

    <dependency>
        <groupId>io.github.harshilsharma63</groupId>
        <artifactId>controller-logger</artifactId>
        <version>1.2.0</version>
    </dependency>
    
  1. Add aspect bean in one of the @Configuration classes

     @Bean
     public GenericControllerAspect genericControllerAspect() {
         return new GenericControllerAspect();
     }
    
  2. Enable logging by adding @Logging annotation on controller classes(s)

     @RestController
     @Logging
     public class MyController {
         ...
     }
    

Data Scrubbing

This library supports hiding sensitive information from being logged. As of now, this works only with method arguments but support for arbitrary fields in objects is on the way.

Data scrubbing is enabled by default and it's recommended to keep it that way.

A method parameter is scrubbed if its name falls withing following criteria:

  • Is one of following values (case insensitive):

    • password
    • passwd
    • secret
    • authorization
    • api_key
    • apikey
    • access_token
    • accesstoken
  • Is contained in custom blacklist provided to setCustomParamBlacklist()

  • Matches custom regex provided to setParamBlacklistRegex()

Value of any param matching above mentioned criteria is scrubbed and replaced by "xxxxx". The scrubbed value can be customized as well by passing in the desired value to setDefaultScrubbedValue() method.

A full example with all customization options used:

@Bean
public GenericControllerAspect genericControllerAspect() {
    GenericControllerAspect aspect = new GenericControllerAspect();

    aspect.setEnableDataScrubbing(true);
    aspect.setDefaultScrubbedValue("*******");
    aspect.setParamBlacklistRegex("account.*");
    aspect.setCustomParamBlacklist(new HashSet<>(Arrays.asList("securityProtocol")));
    return aspect;
}

Customization

Logging is controlled by two annotations @Logging and @NoLogging. The two can be used together to achieve fine-grain control over which methods are logged and which aren't.

Both @Logging and @NoLogging annotations can be used on class as well as methods. Method-level annotation takes priority over class-level annotation. This can be used to enable logging for all controller methods and exclude some, or vice-versa.

    @RestController
    @Logging
    public class MyController {
        
        @RequestMapping("/hello")
        public String hello() {
            // logging will work for this method
        }
        
        @RequestMapping("/bye")
        @NoLogging
        public String bye() {
            // logging will not work for this method
        }
        
    }

Further customizations can be done by extending GenericControllerAspect class, or create your own aspect by implementing ControllerAspect interface.

Future Scope

  • Avoid logging sensitive information such as passwords, cookie data, session information.
  • Test with Spring 5
  • Test with Java 9
  • Add unit tests
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].