UWSLog.LogLevel
Modifier and Type | Field and Description |
---|---|
protected java.io.PrintWriter |
defaultOutput |
protected UWSFileManager |
fileManager |
protected UWSLog.LogLevel |
minLogLevel
Minimum level that a message must have in order to be logged.
|
protected UWS |
uws |
Constructor and Description |
---|
DefaultUWSLog(java.io.OutputStream output)
Builds a
UWSLog which will print all its
messages into the given stream. |
DefaultUWSLog(java.io.PrintWriter writer)
Builds a
UWSLog which will print all its
messages into the given stream. |
DefaultUWSLog(UWS uws)
Builds a
UWSLog which will use the file manager
of the given UWS to get the log output (see UWSFileManager.getLogOutput(uws.service.log.UWSLog.LogLevel, String) ). |
DefaultUWSLog(UWSFileManager fm)
Builds a
UWSLog which will use the given file
manager to get the log output (see UWSFileManager.getLogOutput(uws.service.log.UWSLog.LogLevel, String) ). |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canLog(UWSLog.LogLevel msgLevel)
Tells whether a message with the given error level can be logged or not.
|
void |
debug(java.lang.String msg)
Logs a debug message.
|
void |
debug(java.lang.String msg,
java.lang.Throwable t)
Logs a full (message+exception) debug message.
|
void |
debug(java.lang.Throwable t)
Logs an exception as a debug message.
|
void |
error(java.lang.String msg)
Logs the given error.
|
void |
error(java.lang.String msg,
java.lang.Throwable t)
Logs a full (message+exception) error message.
|
void |
error(java.lang.Throwable t)
Logs the given exception as an error.
|
java.lang.String |
getConfigString()
Get a string representing the configuration of this logger.
|
java.text.DateFormat |
getDateFormat()
Gets the date formatter/parser to use for any date read/write into this logger.
|
protected java.lang.String |
getExceptionOrigin(java.lang.Throwable error)
Format and return the origin of the given error.
|
UWSLog.LogLevel |
getMinLogLevel()
Get the minimum level that a message must have in order to be logged.
|
protected java.io.PrintWriter |
getOutput(UWSLog.LogLevel level,
java.lang.String context)
Gets an output for the given type of message to print.
|
void |
info(java.lang.String msg)
Logs the given information.
|
protected void |
log(UWSLog.LogLevel level,
java.lang.String context,
java.lang.String event,
java.lang.String ID,
java.lang.String message,
java.lang.String addColumn,
java.lang.Throwable error)
Logs a full message and/or error.
|
void |
log(UWSLog.LogLevel level,
java.lang.String context,
java.lang.String message,
java.lang.Throwable error)
Generic way to log a message and/or an exception.
|
void |
logHttp(UWSLog.LogLevel level,
javax.servlet.http.HttpServletRequest request,
java.lang.String requestId,
java.lang.String message,
java.lang.Throwable error)
A message/error logged with this function will have the following format:
|
void |
logHttp(UWSLog.LogLevel level,
javax.servlet.http.HttpServletResponse response,
java.lang.String requestId,
JobOwner user,
java.lang.String message,
java.lang.Throwable error)
A message/error logged with this function will have the following format:
|
void |
logJob(UWSLog.LogLevel level,
UWSJob job,
java.lang.String event,
java.lang.String message,
java.lang.Throwable error)
Log a message and/or an error in the JOB context.
|
void |
logThread(UWSLog.LogLevel level,
java.lang.Thread thread,
java.lang.String event,
java.lang.String message,
java.lang.Throwable error)
Log a message and/or an error in the THREAD context.
|
void |
logUWS(UWSLog.LogLevel level,
java.lang.Object obj,
java.lang.String event,
java.lang.String message,
java.lang.Throwable error)
Log a message and/or an error in the general context of UWS.
|
protected java.lang.String |
normalizeMessage(java.lang.String message)
Normalize a log message.
|
protected void |
printException(java.lang.Throwable error,
java.io.PrintWriter out)
Format and print the given exception inside the given writer.
|
void |
setDateFormat(java.text.DateFormat dateFormat)
Sets the date formatter/parser to use for any date read/write into this logger.
|
void |
setMinLogLevel(UWSLog.LogLevel newMinLevel)
Set the minimum level that a message must have in order to be logged.
|
void |
warning(java.lang.String msg)
Logs the given warning.
|
protected final UWS uws
protected final UWSFileManager fileManager
protected final java.io.PrintWriter defaultOutput
protected UWSLog.LogLevel minLogLevel
Minimum level that a message must have in order to be logged.
The default behavior is the following:
public DefaultUWSLog(UWS uws)
Builds a UWSLog
which will use the file manager
of the given UWS to get the log output (see UWSFileManager.getLogOutput(uws.service.log.UWSLog.LogLevel, String)
).
note 1: This constructor is particularly useful if the file manager of the given UWS may change.
note 2: If no output can be found in the file manager (or if there is no file manager),
the standard error output (System.err
) will be chosen automatically for all log messages.
uws
- A UWS.public DefaultUWSLog(UWSFileManager fm)
Builds a UWSLog
which will use the given file
manager to get the log output (see UWSFileManager.getLogOutput(uws.service.log.UWSLog.LogLevel, String)
).
note 1: This constructor is particularly useful if the way of managing log output may change in the given file manager.
Indeed, the output may change in function of the type of message to log (UWSLog.LogLevel
).
note 2 If no output can be found in the file manager the standard error output (System.err
)
will be chosen automatically for all log messages.
fm
- A UWS file manager.public DefaultUWSLog(java.io.OutputStream output)
Builds a UWSLog
which will print all its
messages into the given stream.
note: the given output will be used whatever is the type of message to log (UWSLog.LogLevel
).
output
- An output stream.public DefaultUWSLog(java.io.PrintWriter writer)
Builds a UWSLog
which will print all its
messages into the given stream.
note: the given output will be used whatever is the type of message to log (UWSLog.LogLevel
).
writer
- A print writer.public java.lang.String getConfigString()
UWSLog
The result of this function aims to be logged when the logging mechanism is successfully configured and ready to be used.
getConfigString
in interface UWSLog
public final UWSLog.LogLevel getMinLogLevel()
Get the minimum level that a message must have in order to be logged.
The default behavior is the following:
public final void setMinLogLevel(UWSLog.LogLevel newMinLevel)
Set the minimum level that a message must have in order to be logged.
The default behavior is the following:
Note: If the given level is NULL, this function has no effect.
newMinLevel
- The new minimum log level.public final java.text.DateFormat getDateFormat()
public final void setDateFormat(java.text.DateFormat dateFormat)
dateFormat
- The date formatter/parser to use from now. (MUST BE DIFFERENT FROM NULL)protected java.io.PrintWriter getOutput(UWSLog.LogLevel level, java.lang.String context)
Gets an output for the given type of message to print.
The System.err
output is used if none can be found in the UWS
or the UWSFileManager
given at the creation, or if the given output stream or writer is NULL.
level
- Level of the message to print (DEBUG, INFO, WARNING, ERROR or FATAL).context
- Context of the message to print (UWS, HTTP, JOB, THREAD).protected java.lang.String normalizeMessage(java.lang.String message)
Normalize a log message.
Since a log entry will a tab-separated concatenation of information, additional tabulations or new-lines would corrupt a log entry. This function replaces such characters by one space. Only \r are definitely deleted.
message
- Log message to normalize.protected boolean canLog(UWSLog.LogLevel msgLevel)
Tells whether a message with the given error level can be logged or not.
In function of the minimum log level of this class, the default behavior is the following:
msgLevel
- Level of the message which has been asked to log. Note: if NULL, it will be considered as DEBUG.public void log(UWSLog.LogLevel level, java.lang.String context, java.lang.String message, java.lang.Throwable error)
UWSLog
Note: The other functions of this class or extension, MAY be equivalent to a call to this function with some specific parameter values. It should be especially the case for the debug(...), info(...), warning(...) and error(...) functions.
log
in interface UWSLog
level
- Level of the error (info, warning, error, ...).
SHOULD NOT be NULL, but if NULL anyway, the level
SHOULD be considered as INFOcontext
- Context of the log item (HTTP, Thread, Job, UWS, ...).
MAY be NULLmessage
- Message to log. MAY be NULLerror
- Error/Exception to log. MAY be NULLprotected final void log(UWSLog.LogLevel level, java.lang.String context, java.lang.String event, java.lang.String ID, java.lang.String message, java.lang.String addColumn, java.lang.Throwable error)
Logs a full message and/or error.
Note: If no message and error is provided, nothing will be written.
level
- Level of the error (DEBUG, INFO, WARNING, ERROR, FATAL). SHOULD NOT be NULLcontext
- Context of the error (UWS, HTTP, THREAD, JOB). MAY be NULLevent
- Context event during which this log is emitted. MAY be NULLID
- ID of the job or HTTP request (it may also be an ID of anything else). MAY BE NULLmessage
- Message of the error. MAY be NULLaddColumn
- Additional column to append after the message and before the stack trace.error
- Error at the origin of the log error/warning/fatal. MAY be NULLprotected void printException(java.lang.Throwable error, java.io.PrintWriter out)
Format and print the given exception inside the given writer.
This function does nothing if the given error is NULL.
The full stack trace is printed ONLY for unknown exceptions.
The printed text has the following format for known exceptions:
Caused by a {ExceptionClassName} {ExceptionOrigin} {ExceptionMessage}
The printed text has the following format for unknown exceptions:
Caused by a {ExceptionFullStackTrace}
error
- The exception to print.out
- The output in which the exception must be written.getExceptionOrigin(Throwable)
protected java.lang.String getExceptionOrigin(java.lang.Throwable error)
Format and return the origin of the given error. "Origin" means here: "where the error has been thrown from?" (from which class? method? file? line?).
This function does nothing if the given error is NULL or if the origin information is missing.
The returned text has the following format:
at {OriginClass}.{OriginMethod}({OriginFile}:{OriginLine})
{OriginFile} and {OriginLine} are written only if provided.
error
- Error whose the origin should be returned.public void debug(java.lang.String msg)
UWSLog
Note:
This function should be equals to:
log(LogLevel.WARNING, null, msg, null)
public void debug(java.lang.Throwable t)
UWSLog
Note:
This function should be equals to:
log(LogLevel.WARNING, null, null, t)
public void debug(java.lang.String msg, java.lang.Throwable t)
UWSLog
Note:
This function should be equals to:
log(LogLevel.WARNING, null, msg, t)
public void info(java.lang.String msg)
UWSLog
Note:
This function should be equals to:
log(LogLevel.INFO, null, msg, null)
public void warning(java.lang.String msg)
UWSLog
Note:
This function should be equals to:
log(LogLevel.WARNING, null, msg, null)
public void error(java.lang.String msg)
UWSLog
Note:
This function should be equals to:
log(LogLevel.ERROR, null, msg, null)
public void error(java.lang.Throwable t)
UWSLog
Note:
This function should be equals to:
log(LogLevel.ERROR, null, null, t)
public void error(java.lang.String msg, java.lang.Throwable t)
UWSLog
Note:
This function should be equals to:
log(LogLevel.ERROR, null, msg, t)
public void logHttp(UWSLog.LogLevel level, javax.servlet.http.HttpServletRequest request, java.lang.String requestId, java.lang.String message, java.lang.Throwable error)
A message/error logged with this function will have the following format:
<TIMESTAMP> <LEVEL> HTTP REQUEST_RECEIVED <REQUEST_ID> <MESSAGE> <HTTP_METHOD> in <CONTENT_TYPE> at <URL> from <IP_ADDR> using <USER_AGENT> with parameters (<PARAM1>=<VAL1>&...)
logHttp
in interface UWSLog
level
- Level of the log (info, warning, error, ...).
SHOULD NOT be NULL, but if NULL anyway, the level
SHOULD be considered as INFOrequest
- HTTP request received by the service.
SHOULD NOT be NULLrequestId
- ID to use to identify this request until its response is
sent.message
- Message to log. MAY be NULLerror
- Error/Exception to log. MAY be NULLUWSLog.logHttp(uws.service.log.UWSLog.LogLevel, javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String, java.lang.Throwable)
public void logHttp(UWSLog.LogLevel level, javax.servlet.http.HttpServletResponse response, java.lang.String requestId, JobOwner user, java.lang.String message, java.lang.Throwable error)
A message/error logged with this function will have the following format:
<TIMESTAMP> <LEVEL> HTTP RESPONSE_SENT <REQUEST_ID> <MESSAGE> HTTP-<STATUS_CODE> to the user <USER> as <CONTENT_TYPE>
,where <USER> may be either "(id:<USER_ID>;pseudo:<USER_PSEUDO>)" or "ANONYMOUS".
logHttp
in interface UWSLog
level
- Level of the log (info, warning, error, ...).
SHOULD NOT be NULL, but if NULL anyway, the level
SHOULD be considered as INFOresponse
- HTTP response sent by the service to the client.
MAY be NULL if an error occurs while writing the
responserequestId
- ID to use to identify the request to which the given
response is answering.user
- Identified user which has sent the received request.message
- Message to log. MAY be NULLerror
- Error/Exception to log. MAY be NULLUWSLog.logHttp(uws.service.log.UWSLog.LogLevel, javax.servlet.http.HttpServletResponse, java.lang.String, uws.job.user.JobOwner, java.lang.String, java.lang.Throwable)
public void logUWS(UWSLog.LogLevel level, java.lang.Object obj, java.lang.String event, java.lang.String message, java.lang.Throwable error)
UWSLog
One of the parameter is of type Object
. This object can be used
to provide more information to the log function in order to describe as
much as possible the state and/or result event.
List of all events sent by the library (case sensitive):
UWS
except in case of
error where "obj" is NULL)JobList
)JobList
)UWSUrl
)UWSUrl
)HttpServletRequest
in case of error)Result
)ErrorSummary
)JSONObject
or JSONArray
or NULL))JobOwner
,
a UWSJob
, ...)UWS
)logUWS
in interface UWSLog
level
- Level of the log (info, warning, error, ...).
SHOULD NOT be NULL, but if NULL anyway, the level
SHOULD be considered as INFOobj
- Object providing more information about the event/object
at the origin of this log. MAY be NULLevent
- Event at the origin of this log or action currently
executed by UWS while this log is sent.
MAY be NULLmessage
- Message to log. MAY be NULLerror
- Error/Exception to log. MAY be NULLpublic void logJob(UWSLog.LogLevel level, UWSJob job, java.lang.String event, java.lang.String message, java.lang.Throwable error)
UWSLog
List of all events sent by the library (case sensitive):
logJob
in interface UWSLog
level
- Level of the log (info, warning, error, ...).
SHOULD NOT be NULL, but if NULL anyway, the level
SHOULD be considered as INFOjob
- Job from which this log comes. MAY be NULLevent
- Event at the origin of this log or action executed by
the given job while this log is sent. MAY be NULLmessage
- Message to log. MAY be NULLerror
- Error/Exception to log. MAY be NULLpublic void logThread(UWSLog.LogLevel level, java.lang.Thread thread, java.lang.String event, java.lang.String message, java.lang.Throwable error)
UWSLog
Log a message and/or an error in the THREAD context.
List of all events sent by the library (case sensitive):
logThread
in interface UWSLog
level
- Level of the log (info, warning, error, ...).
SHOULD NOT be NULL, but if NULL anyway, the level
SHOULD be considered as INFOthread
- Thread from which this log comes. MAY be NULLevent
- Event at the origin of this log or action currently
executed by the given thread while this log is sent.
MAY be NULLmessage
- Message to log. MAY be NULLerror
- Error/Exception to log. MAY be NULL