Logging
Module for declarative logging of method arguments and result using annotations.
Dependency¶
Most likely already transitively connected from other dependencies or from Logback, otherwise it needs to be added:
Dependency build.gradle
:
Module:
Dependency build.gradle.kts
:
Module:
Logging¶
It is expected to use special combinations of annotations to customize method logging.
Argument¶
@Log.in
public String methodWithReturnAndOnlyLogArgs(@Log.off String strParam,int numParam) {
return"testResult";
}
Logging Level | Logging |
---|---|
TRACE, DEBUG |
DEBUG [] r.t.e.e.Example.methodWithArgs: > {data: {numParam: "4"}} |
INFO |
INFO [] r.t.e.e.Example.methodWithArgs: > |
Result¶
@Log.out
public String methodWithOnlyLogReturnAndArgs(String strParam, int numParam) {
return "testResult"
}
Logging level | Logging |
---|---|
TRACE, DEBUG |
DEBUG [] r.t.e.e.Example.methodWithArgs: < {data: {out: "testResult"}} |
INFO |
INFO [] r.t.e.e.Example.methodWithArgs: < |
Argument and result¶
Logging Level | Logging |
---|---|
TRACE, DEBUG |
DEBUG [] r.t.e.e.Example.methodWithArgs: > {data: {strParam: "s", numParam: "4"}} DEBUG [] r.t.e.e.Example.methodWithArgs: < {data: {out: "testResult"}} |
INFO |
INFO [] r.t.e.e.Example.methodWithArgs: > INFO [] r.t.e.e.Example.methodWithArgs: < |
Selective logging¶
@Log.out
@Log.off
public String methodWithOnlyLogReturnAndArgs(String strParam,int numParam) {
return"testResult";
}
Logging Level | Logging |
---|---|
TRACE, DEBUG |
INFO [] r.t.e.e.Example.methodWithArgs: < |
INFO |
INFO [] r.t.e.e.Example.methodWithArgs: < |
Signatures¶
Available signatures for repository methods out of the box:
Class must be non final
in order for aspects to work.
The T
refers to the type of the return value, either Void
.
T myMethod()
Optional<T> myMethod()
CompletionStage<T> myMethod()
CompletionStageMono<T> myMethod()
Project Reactor (require dependency)Flux<T> myMethod()
Project Reactor (require dependency)
Class must be open
in order for aspects to work.
By T
we mean the type of the return value, either T?
, either Unit
.
myMethod(): T
suspend myMethod(): T
Kotlin Coroutine (require dependency asimplementation
)myMethod(): Flow<T>
Kotlin Coroutine (require dependency asimplementation
)