@Deprecated public class BasicRestLogger extends Object implements RestLogger
Subclasses can override these methods to tailor logging of HTTP requests.
Subclasses MUST implement a no-arg public constructor.
RestLogger.Null
Constructor and Description |
---|
BasicRestLogger(RestContext context)
Deprecated.
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected Logger |
getLogger()
Deprecated.
Returns the Java logger used for logging.
|
protected String |
getLoggerName()
Deprecated.
Returns the logger name.
|
void |
log(Level level,
String msg,
Object... args)
Deprecated.
Log a message.
|
void |
log(Level level,
Throwable cause,
String msg,
Object... args)
Deprecated.
Log a message to the logger.
|
void |
logObjects(Level level,
String msg,
Object... args)
Deprecated.
Same as
log(Level, String, Object...) excepts runs the arguments through JsonSerializer.DEFAULT_READABLE . |
void |
onError(HttpServletRequest req,
HttpServletResponse res,
RestException e)
Deprecated.
Callback method for logging errors during HTTP requests.
|
void |
setLevel(Level level)
Deprecated.
Sets the logging level for this logger.
|
protected boolean |
shouldLog(HttpServletRequest req,
HttpServletResponse res,
RestException e)
Deprecated.
Returns
|
protected boolean |
shouldLogStackTrace(HttpServletRequest req,
HttpServletResponse res,
RestException e)
Deprecated.
Returns
|
public BasicRestLogger(RestContext context)
context
- The context of the resource object.protected String getLoggerName()
By default returns the class name of the servlet class passed in to the context.
Subclasses can override this to provide their own customized logger names.
protected Logger getLogger()
Subclasses can provide their own logger.
The default implementation returns the logger created using
public void setLevel(Level level)
RestLogger
setLevel
in interface RestLogger
level
- The new level.public void log(Level level, Throwable cause, String msg, Object... args)
Subclasses can override this method if they wish to log messages using a library other than Java Logging (e.g. Apache Commons Logging).
log
in interface RestLogger
level
- The log level.cause
- The cause.msg
- The message to log.args
- Optional MessageFormat
-style arguments.public void log(Level level, String msg, Object... args)
Equivalent to calling log(level,
log
in interface RestLogger
level
- The log level.msg
- The message to log.args
- Optional MessageFormat
-style arguments.public void logObjects(Level level, String msg, Object... args)
log(Level, String, Object...)
excepts runs the arguments through JsonSerializer.DEFAULT_READABLE
.
Serialization of arguments do not occur if message is not logged, so it's safe to use this method from within debug log statements.
logObjects(
logObjects
in interface RestLogger
level
- The log level.msg
- The message to log.args
- Optional MessageFormat
-style arguments.public void onError(HttpServletRequest req, HttpServletResponse res, RestException e)
Typically, subclasses will override this method and log errors themselves.
The default implementation simply logs errors to the
Here's a typical implementation showing how stack trace hashing can be used to reduce log file sizes...
onError
in interface RestLogger
req
- The servlet request object.res
- The servlet response object.e
- Exception indicating what error occurred.protected boolean shouldLog(HttpServletRequest req, HttpServletResponse res, RestException e)
Subclasses can override this method to provide their own logic for determining when exceptions are logged.
The default implementation will return
req
- The HTTP request.res
- The HTTP response.e
- The exception.protected boolean shouldLogStackTrace(HttpServletRequest req, HttpServletResponse res, RestException e)
Subclasses can override this method to provide their own logic for determining when stack traces are logged.
The default implementation will only log a stack trace if RestException.getOccurrence()
returns
req
- The HTTP request.res
- The HTTP response.e
- The exception.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.