View Javadoc

1   package com.github.sfleiter.cdi_interceptors;
2   
3   import java.lang.annotation.ElementType;
4   import java.lang.annotation.Retention;
5   import java.lang.annotation.RetentionPolicy;
6   import java.lang.annotation.Target;
7   
8   import javax.enterprise.util.Nonbinding;
9   import javax.interceptor.InterceptorBinding;
10  
11  import uk.org.lidalia.slf4jext.Level;
12  
13  /**
14   * Activates automatic method-level logging for any annotated bean. For every
15   * call a single slf4j log message is generated with the logger set to the name
16   * of the class. The message contains the method name, the parameters, the
17   * result object, the call duration and the exception if one got thrown.
18   * 
19   * @author Stefan Fleiter
20   */
21  @InterceptorBinding
22  @Target({ ElementType.METHOD, ElementType.TYPE })
23  @Retention(RetentionPolicy.RUNTIME)
24  public @interface Logging {
25  
26      /**
27       * Default limit of items per collection or array instance that are logged.
28       */
29      final int LOG_ITEM_LIMIT_DEFAULT = 5;
30  
31      /**
32       * Log Level for successful calls (not throwing an Exception) and those that
33       * throw Exceptions not configured as severe. Defaults to {@Link
34       * Level.INFO}.
35       */
36      @Nonbinding
37      Level standardLogLevel() default Level.INFO;
38  
39      /**
40       * Log Level for calls that throw an Exception configured as severe.
41       * Defaults to {@Link Level.ERROR}.
42       */
43      @Nonbinding
44      Level severeExceptionLogLevel() default Level.ERROR;
45  
46      /**
47       * Maximum number of items in a single array or collection that are logged.
48       * For recursive items (collection as part of an array, f.e.) the number of
49       * items logged for a parameter or the result can be greater than that.
50       * Defaults to {@link Logging#LOG_ITEM_LIMIT_DEFAULT}.
51       */
52      @Nonbinding
53      int logItemLimit() default LOG_ITEM_LIMIT_DEFAULT;
54  
55      /**
56       * If true the duration of the method call is added to the log message.
57       * Defaults to true.
58       */
59      @Nonbinding
60      boolean measureDuration() default true;
61  }