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;
014
015import java.text.*;
016import java.util.logging.*;
017
018import javax.servlet.http.*;
019
020import org.apache.juneau.json.*;
021
022/**
023 * Logging utility class.
024 *
025 * <div class='warn'>
026 *    <b>Deprecated</b> - Use {@link RestCallLogger}
027 * </div>
028 *
029 * <ul class='seealso'>
030 *    <li class='jf'>{@link RestContext#REST_logger}
031 *    <li class='link'>{@doc RestLoggingAndDebugging}
032 * </ul>
033 */
034@Deprecated
035public interface RestLogger {
036
037   /**
038    * Represents no RestLogger.
039    *
040    * <p>
041    * Used on annotation to indicate that the value should be inherited from the parent class, and
042    * ultimately {@link BasicRestLogger} if not specified at any level.
043    */
044   public interface Null extends RestLogger {}
045
046   /**
047    * Sets the logging level for this logger.
048    *
049    * @param level The new level.
050    */
051   public void setLevel(Level level);
052
053   /**
054    * Log a message to the logger.
055    *
056    * @param level The log level.
057    * @param cause The cause.
058    * @param msg The message to log.
059    * @param args Optional {@link MessageFormat}-style arguments.
060    */
061   public void log(Level level, Throwable cause, String msg, Object...args);
062
063   /**
064    * Log a message.
065    *
066    * @param level The log level.
067    * @param msg The message to log.
068    * @param args Optional {@link MessageFormat}-style arguments.
069    */
070   public void log(Level level, String msg, Object...args);
071
072   /**
073    * Same as {@link #log(Level, String, Object...)} excepts runs the arguments through {@link SimpleJsonSerializer#DEFAULT_READABLE}.
074    *
075    * <p>
076    * Serialization of arguments do not occur if message is not logged, so it's safe to use this method from within
077    * debug log statements.
078    *
079    * <h5 class='section'>Example:</h5>
080    * <p class='bcode w800'>
081    *    logObjects(<jsf>DEBUG</jsf>, <js>"Pojo contents:\n{0}"</js>, myPojo);
082    * </p>
083    *
084    * @param level The log level.
085    * @param msg The message to log.
086    * @param args Optional {@link MessageFormat}-style arguments.
087    */
088   public void logObjects(Level level, String msg, Object...args);
089
090   /**
091    * Callback method for logging errors during HTTP requests.
092    *
093    * <p>
094    * Typically, subclasses will override this method and log errors themselves.
095    *
096    * <p>
097    * The default implementation simply logs errors to the <c>RestServlet</c> logger.
098    *
099    * <p>
100    * Here's a typical implementation showing how stack trace hashing can be used to reduce log file sizes...
101    * <p class='bcode w800'>
102    *    <jk>protected void</jk> onError(HttpServletRequest req, HttpServletResponse res, RestException e, <jk>boolean</jk> noTrace) {
103    *       String qs = req.getQueryString();
104    *       String msg = <js>"HTTP "</js> + req.getMethod() + <js>" "</js> + e.getStatus() + <js>" "</js> + req.getRequestURI() + (qs == <jk>null</jk> ? <js>""</js> : <js>"?"</js> + qs);
105    *       <jk>int</jk> c = e.getOccurrence();
106    *
107    *       <jc>// REST_useStackTraceHashes is disabled, so we have to log the exception every time.</jc>
108    *       <jk>if</jk> (c == 0)
109    *          myLogger.log(Level.<jsf>WARNING</jsf>, <jsm>format</jsm>(<js>"[%s] %s"</js>, e.getStatus(), msg), e);
110    *
111    *       <jc>// This is the first time we've countered this error, so log a stack trace
112    *       // unless ?noTrace was passed in as a URL parameter.</jc>
113    *       <jk>else if</jk> (c == 1 &amp;&amp; ! noTrace)
114    *          myLogger.log(Level.<jsf>WARNING</jsf>, <jsm>format</jsm>(<js>"[%h.%s.%s] %s"</js>, e.hashCode(), e.getStatus(), c, msg), e);
115    *
116    *       <jc>// This error occurred before.
117    *       // Only log the message, not the stack trace.</jc>
118    *       <jk>else</jk>
119    *          myLogger.log(Level.<jsf>WARNING</jsf>, <jsm>format</jsm>(<js>"[%h.%s.%s] %s, %s"</js>, e.hashCode(), e.getStatus(), c, msg, e.getLocalizedMessage()));
120    *    }
121    * </p>
122    *
123    * @param req The servlet request object.
124    * @param res The servlet response object.
125    * @param e Exception indicating what error occurred.
126    */
127   public void onError(HttpServletRequest req, HttpServletResponse res, RestException e);
128}