public class Slf4jUWSLog extends java.lang.Object implements UWSLog
UWSLog
forwards all log submission to
SLF4J.
Thus, a UWS implementor can choose how to deal with logs. SLF4J already provides bridges at least for the following logging frameworks:
A different logger is used in function of the log entry's CONTEXT. Four values are supported: "UWS", "HTTP", "JOB" and "THREAD". If a different value is set for the CONTEXT, the general/root logger will be used.
The ID of each logger follows this rule:
"uws.service"{SUFFIX}
The ID of the general/root logger is just
"uws.service"
. For all the other specific
loggers, {SUFFIX}
is a dot followed by one among
"UWS", "HTTP",
"JOB" and "THREAD". Thus, the
full ID of the logger for the HTTP requests is:
uws.service.httpLog entries format
All log entries are formatted as follow:
{EVENT} - {ID} - {MESSAGE} - {ADDITIONAL_DATA}
{EVENT}, {ID} and {ADDITIONAL_DATA} may not be all provided for some messages ; all are optional, and especially ADDITIONAL_DATA. When not provided, each is replaced by an empty string. In the special case of ADDITIONAL_DATA, if none is provided, the " - " prefixing it is not written.
UWSLog.LogLevel
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
DEFAULT_ROOT_LOG_ID
Default SLF4J identifier for the general/root logger to use.
|
protected static java.lang.String |
HTTP_LOG_ID_SUFFIX
Suffix to append to the root logger ID for the HTTP logger.
|
protected org.slf4j.Logger |
httpLogger
Logger for HTTP requests and responses.
|
protected static java.lang.String |
JOB_LOG_ID_SUFFIX
Suffix to append to the root logger ID for the JOB logger.
|
protected org.slf4j.Logger |
jobLogger
Logger for UWS jobs actions.
|
protected org.slf4j.Logger |
rootLogger
General purpose logger.
|
protected static java.lang.String |
THREAD_LOG_ID_SUFFIX
Suffix to append to the root logger ID for the THREAD logger.
|
protected org.slf4j.Logger |
threadLogger
Logger for UWS jobs' threads actions.
|
protected static java.lang.String |
UWS_LOG_ID_SUFFIX
Suffix to append to the root logger ID for the UWS logger.
|
protected org.slf4j.Logger |
uwsLogger
Logger for general UWS actions.
|
Modifier | Constructor and Description |
---|---|
|
Slf4jUWSLog()
Initialise this logger.
|
protected |
Slf4jUWSLog(java.lang.String logId)
Initialise this logger with the specified SLF4J logger.
|
Modifier and Type | Method and Description |
---|---|
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.
|
void |
info(java.lang.String msg)
Logs the given information.
|
protected void |
log(UWSLog.LogLevel level,
org.slf4j.Logger logger,
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)
Log a message and/or an error in the HTTP context.
|
void |
logHttp(UWSLog.LogLevel level,
javax.servlet.http.HttpServletResponse response,
java.lang.String requestId,
JobOwner user,
java.lang.String message,
java.lang.Throwable error)
Log a message and/or an error in the HTTP context.
|
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.
|
void |
warning(java.lang.String msg)
Logs the given warning.
|
protected static final java.lang.String DEFAULT_ROOT_LOG_ID
protected static final java.lang.String UWS_LOG_ID_SUFFIX
protected static final java.lang.String HTTP_LOG_ID_SUFFIX
protected static final java.lang.String JOB_LOG_ID_SUFFIX
protected static final java.lang.String THREAD_LOG_ID_SUFFIX
protected final org.slf4j.Logger rootLogger
protected final org.slf4j.Logger uwsLogger
protected final org.slf4j.Logger httpLogger
protected final org.slf4j.Logger jobLogger
protected final org.slf4j.Logger threadLogger
public Slf4jUWSLog()
protected Slf4jUWSLog(java.lang.String logId)
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 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, org.slf4j.Logger logger, 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 NULLlogger
- Logger to use. MUST NOT 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 NULLpublic 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)
UWSLog
Note:
When a request is received, this function is called, and then, when the
response has been written and sent to the client,
UWSLog.logHttp(LogLevel, HttpServletResponse, String, JobOwner, String, Throwable)
should be called. These functions should always work together.
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(LogLevel, HttpServletResponse, String, JobOwner, String, 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)
UWSLog
Note:
When a request is received, UWSLog.logHttp(LogLevel, HttpServletRequest, String, String, Throwable)
is called, and then, when the response has been written and sent to the
client, this function should be called. These functions should always
work together.
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(LogLevel, HttpServletRequest, String, String, 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