Annotation Type Loggable
-
@Documented @Retention(RUNTIME) @Target({METHOD,TYPE}) public @interface Loggable
Makes a method loggable viaLogger
.For example, this
load()
method produces a log line on every call:@Loggable String load(String resource) throws IOException { return "something"; }
You can configure the level of logging:
@Loggable(Loggable.DEBUG) void save(String resource) throws IOException { // do something }
Since version 0.7.6, you can specify a maximum execution time limit for a method. If such a limit is reached a logging message will be issued with a
WARN
priority. It is a very convenient mechanism for profiling applications in production. Default value of a limit is 1 second.@Loggable(limit = 2) void save(String resource) throws IOException { // do something, potentially slow }
Since version 0.7.14 you can change the time unit for the "limit" parameter. Default unit of measurement is a second:
@Loggable(limit = 200, unit = TimeUnit.MILLISECONDS) void save(String resource) throws IOException { // do something, potentially slow }
Since version 0.7.17 you can ignore certain exception types, and they won't be logged when thrown. It is very useful when exceptions are used to control flow (which is not a good practice, but is still used in some frameworks, for example in JAX-RS):
@Loggable(ignore = WebApplicationException.class) String get() { if (not_logged_in()) { throw new WebApplicationException(forward_to_login_page()); } }
Since version 0.8 you can mark some exceptions as "always to be ignored", using
Loggable.Quiet
annotation.- Since:
- 0.7.2
- See Also:
Logger
, http://aspects.jcabi.com/, Java Method Logging with AOP and Annotations, by Yegor Bugayenko
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description Class<? extends Throwable>[]
ignore
List of exception types, which should not be logged if thrown.int
limit
Maximum amount allowed for this method (a warning will be issued if it takes longer).boolean
logThis
Add toString() result to log line.String
name
The name of the logger to be used.int
precision
The precision (number of fractional digits) to be used when displaying the measured execution time.boolean
prepend
Method entry moment should be reported as well (by default only an exit moment is reported).boolean
skipArgs
Skip logging of arguments, replacing them all with dots?boolean
skipResult
Skip logging of result, replacing it with dots?boolean
trim
Shall we trim long texts in order to make log lines more readable?TimeUnit
unit
Time unit for the limit.int
value
Level of logging.
-
-
-
-
unit
TimeUnit unit
Time unit for the limit.- Returns:
- The time unit
- Since:
- 0.7.14
- Default:
- java.util.concurrent.TimeUnit.MINUTES
-
-
-
ignore
Class<? extends Throwable>[] ignore
List of exception types, which should not be logged if thrown.You can also mark some exception types as "always to be ignored", using
Loggable.Quiet
annotation.- Returns:
- Array of types
- Since:
- 0.7.17
- Default:
- {}
-
-
-
name
String name
The name of the logger to be used. If not specified, defaults to the class name of the annotated class or method.- Returns:
- The logger's name
- Since:
- 0.18
- Default:
- ""
-
-