001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.annotation;
014
015import java.util.logging.*;
016
017import org.apache.juneau.rest.*;
018
019/**
020 * Configures the {@link RestCallLogger} used by REST classes and methods.
021 *
022 * <p>
023 * This annotation can be used on the {@link Rest#logging()} and {@link RestMethod#logging()} annotations
024 * to control how and when HTTP requests are logged and at what level of detail.
025 *
026 * <h5 class='section'>Example:</h5>
027 * <p class='bcode w800'>
028 *    <ja>@Rest</ja>(
029 *       logging=<ja>@Logging</ja>(
030 *          level=<js>"INFO"</js>,
031 *          rules={
032 *             <ja>@LoggingRule</ja>(codes=<js>"400-499"</js>, level=<js>"WARNING"</js>, req=<js>"SHORT"</js>, res=<js>"MEDIUM"</js>),
033 *             <ja>@LoggingRule</ja>(codes=<js>">=500"</js>, level=<js>"SEVERE"</js>, req=<js>"LONG"</js>, res=<js>"LONG"</js>)
034 *          }
035 *       }
036 *    )
037 *    <jk>public class</jk> MyResource {
038 *
039 *       <ja>@RestMethod</ja>(
040 *          logging=<ja>@Logging</ja>(
041 *             level=<js>"WARNING"</js>,
042 *             rules={
043 *                <ja>@LoggingRule</ja>(codes=<js>"400-499"</js>, level=<js>"SEVERE"</js>, req=<js>"LONG"</js>, res=<js>"LONG"</js>)
044 *             }
045 *          }
046 *       )
047 *       <jk>public</jk> String getFoo() {...}
048 *    }
049 * <p>
050 *
051 * <p>
052 * This annotation is inheritable from parent classes and overridable by child classes.  When defined on multiple levels,
053 * the annotation values are combined.
054 * <br>Rules defined on child classes are matched before rules defined on parent classes.
055 *
056 * <ul class='seealso'>
057 *    <li class='link'>{@doc juneau-rest-server.LoggingAndDebugging}
058 *    <li class='jf'>{@link RestContext#REST_callLoggerConfig}
059 *    <li class='jf'>{@link RestMethodContext#RESTMETHOD_callLoggerConfig}
060 * </ul>
061 */
062public @interface Logging {
063
064   /**
065    * Disables logging entirely for this servlet or method.
066    *
067    * <p>
068    * The possible values are (case-insensitive):
069    * <ul>
070    *    <li><js>"true</jk> - Disable logging.
071    *    <li><js>"false"</jk> (default) - Don't disable logging.
072    *    <li><js>"per-request"</jk> - Disable logging if No-Trace is set on the request.
073    * </ul>
074    *
075    * <p>
076    * The No-Trace setting on a request can be set by adding <c class='snippet'>X-NoTrace: true</c> to the request header.
077    * It can also be set programmatically by calling either the {@link RestRequest#setNoTrace(Boolean)} or
078    * {@link RestResponse#setNoTrace(Boolean)} methods.
079    *
080    * <p>
081    * Setting this value to <js>"true"</js> is equivalent to setting the level to <js>"off"</js>.
082    *
083    * <ul class='notes'>
084    *    <li>
085    *       Supports {@doc DefaultRestSvlVariables}
086    *       (e.g. <js>"$L{my.localized.variable}"</js>).
087    * </ul>
088    *
089    * <ul class='seealso'>
090    *    <li class='link'>{@doc juneau-rest-server.LoggingAndDebugging}
091    * </ul>
092    */
093   public String disabled() default "";
094
095   /**
096    * Identifies the logging level at which to log REST calls.
097    *
098    * <p>
099    * See the {@link Level} class for possible values.
100    *
101    * <p>
102    * Values are case-insensitive.
103    *
104    * <p>
105    * The default level is {@link Level#INFO}.
106    *
107    * <p>
108    * {@link Level#OFF} can be used to turn off logging.
109    *
110    * <ul class='notes'>
111    *    <li>
112    *       Supports {@doc DefaultRestSvlVariables}
113    *       (e.g. <js>"$L{my.localized.variable}"</js>).
114    * </ul>
115    *
116    * <ul class='seealso'>
117    *    <li class='link'>{@doc juneau-rest-server.LoggingAndDebugging}
118    * </ul>
119    */
120   public String level() default "";
121
122   /**
123    * Defines the rules to use for logging REST calls.
124    *
125    * <p>
126    * No defines rules results in no logged messages.
127    *
128    * <ul class='seealso'>
129    *    <li class='link'>{@doc juneau-rest-server.LoggingAndDebugging}
130    * </ul>
131    */
132   public LoggingRule[] rules() default {};
133
134   /**
135    * Specifies the time in milliseconds to cache stack trace hashes.
136    *
137    * <p>
138    * This setting can be used to periodically log stack traces (e.g. every 24 hours) so that stack traces don't get
139    * lost from rolling-over log files.
140    *
141    * <ul class='notes'>
142    *    <li>
143    *       Supports {@doc DefaultRestSvlVariables}
144    *       (e.g. <js>"$L{my.localized.variable}"</js>).
145    * </ul>
146    *
147    * <ul class='seealso'>
148    *    <li class='link'>{@doc juneau-rest-server.LoggingAndDebugging}
149    * </ul>
150    */
151   public String stackTraceHashingTimeout() default "";
152
153   /**
154    * Specifies whether to use stack trace hashing in the log file.
155    *
156    * <p>
157    * This setting can be used to eliminate duplicate stacktraces in your log file by logging them once and then
158    * logging identifying hash IDs.
159    *
160    * <p>
161    * The possible values are (case-insensitive):
162    * <ul>
163    *    <li><js>"true</jk> - Use stack trace hashing.
164    *    <li><js>"false"</jk> (default) - Don't use stack trace hashing.
165    * </ul>
166    *
167    * <ul class='notes'>
168    *    <li>
169    *       Supports {@doc DefaultRestSvlVariables}
170    *       (e.g. <js>"$L{my.localized.variable}"</js>).
171    * </ul>
172    *
173    * <ul class='seealso'>
174    *    <li class='link'>{@doc juneau-rest-server.LoggingAndDebugging}
175    * </ul>
176    */
177   public String useStackTraceHashing() default "";
178}