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
WARNpriority. 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.Quietannotation.- 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>[]ignoreList of exception types, which should not be logged if thrown.intlimitMaximum amount allowed for this method (a warning will be issued if it takes longer).booleanlogThisAdd toString() result to log line.StringnameThe name of the logger to be used.intprecisionThe precision (number of fractional digits) to be used when displaying the measured execution time.booleanprependMethod entry moment should be reported as well (by default only an exit moment is reported).booleanskipArgsSkip logging of arguments, replacing them all with dots?booleanskipResultSkip logging of result, replacing it with dots?booleantrimShall we trim long texts in order to make log lines more readable?TimeUnitunitTime unit for the limit.intvalueLevel 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.Quietannotation.- 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:
- ""
-
-