Package org.restlet.service
Class LogService
- java.lang.Object
-
- org.restlet.service.Service
-
- org.restlet.service.LogService
-
public class LogService extends Service
Service providing access logging service. The implementation is fully based on the standard logging mechanism introduced in JDK 1.4.
The default access log format follows the W3C Extended Log File Format with the following fields used:
- Date (YYYY-MM-DD)
- Time (HH:MM:SS)
- Client address (IP)
- Remote user identifier (see RFC 1413)
- Server address (IP)
- Server port
- Method (GET|POST|...)
- Resource reference path (including the leading slash)
- Resource reference query (excluding the leading question mark)
- Response status code
- Number of bytes sent
- Number of bytes received
- Time to serve the request (in milliseconds)
- Host reference
- Client agent name
- Referrer reference
If you use Analog to generate your log reports, and if you use the default log format, then you can simply specify this string as a value of the LOGFORMAT command: (%Y-%m-%d\t%h:%n:%j\t%S\t%u\t%j\t%j\t%j\t%r\t%q\t%c\t%b\t%j\t%T\t%v\t%B\t%f)
For custom access log format, see the syntax to use and the list of available variable names inTemplate
.- Author:
- Jerome Louvel
- See Also:
- User Guide - Access logging, java.util.logging
-
-
Field Summary
Fields Modifier and Type Field Description protected Template
responseLogTemplate
The response log template to use.
-
Constructor Summary
Constructors Constructor Description LogService()
Constructor.LogService(boolean enabled)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Filter
createInboundFilter(Context context)
Create the filter that should be invoked for incoming calls.protected java.lang.String
getDefaultResponseLogMessage(Response response, int duration)
Format a log entry using the default IIS log format.Template
getLoggableTemplate()
Returns the URI template of loggable resource references.java.lang.String
getLoggerName()
Returns the name of the JDK's logger to use when logging access calls.Reference
getLogPropertiesRef()
Returns the URI reference of the log properties.java.lang.String
getResponseLogFormat()
Returns the format used when logging responses.java.lang.String
getResponseLogMessage(Response response, int duration)
Format an access log entry.protected boolean
isDebugging()
Deprecated.Rely onApplication.isDebugging()
instead.boolean
isIdentityCheck()
Indicates if the identity check (as specified by RFC1413) is enabled.boolean
isLoggable(Request request)
Indicates if the call should be logged during the processing chain.protected void
setDebugging(boolean debugging)
Deprecated.Rely onApplication.setDebugging(boolean)
instead.void
setIdentityCheck(boolean identityCheck)
Indicates if the identity check (as specified by RFC1413) is enabled.void
setLoggableTemplate(java.lang.String loggableTemplateRef)
Sets the URI template of loggable resource references.void
setLoggableTemplate(Template loggableTemplate)
Sets the URI template of loggable resource references.void
setLoggerName(java.lang.String name)
Sets the name of the JDK's logger to use when logging access calls.void
setLogPropertiesRef(java.lang.String logPropertiesUri)
Sets the URI reference of the log properties.void
setLogPropertiesRef(Reference logPropertiesRef)
Sets the URI reference of the log properties.void
setResponseLogFormat(java.lang.String responseLogFormat)
Sets the format to use when logging responses.void
start()
Starts the log service by attempting to read the log properties if thegetLogPropertiesRef()
returns a non null URI reference.-
Methods inherited from class org.restlet.service.Service
createOutboundFilter, getContext, isEnabled, isStarted, isStopped, setContext, setEnabled, stop
-
-
-
-
Field Detail
-
responseLogTemplate
protected volatile Template responseLogTemplate
The response log template to use.
-
-
Method Detail
-
createInboundFilter
public Filter createInboundFilter(Context context)
Description copied from class:Service
Create the filter that should be invoked for incoming calls.- Overrides:
createInboundFilter
in classService
- Parameters:
context
- The current context.- Returns:
- The new filter or null.
-
getDefaultResponseLogMessage
protected java.lang.String getDefaultResponseLogMessage(Response response, int duration)
Format a log entry using the default IIS log format.- Parameters:
response
- The response to log.duration
- The call duration (in milliseconds).- Returns:
- The formatted log entry.
-
getLoggableTemplate
public Template getLoggableTemplate()
Returns the URI template of loggable resource references. Returns null by default, meaning the all requests are loggable, independant of their target resource URI reference.- Returns:
- The URI template of loggable resource references.
- See Also:
Request.getResourceRef()
-
getLoggerName
public java.lang.String getLoggerName()
Returns the name of the JDK's logger to use when logging access calls. The default name will follow this pattern: "org.restlet.MyComponent.LogService", where "MyComponent" will correspond to the simple class name of your component subclass or to the base "Component" class.- Returns:
- The name of the JDK's logger to use when logging access calls.
-
getLogPropertiesRef
public Reference getLogPropertiesRef()
Returns the URI reference of the log properties.- Returns:
- The URI reference of the log properties.
-
getResponseLogFormat
public java.lang.String getResponseLogFormat()
Returns the format used when logging responses.- Returns:
- The format used, or null if the default one is used.
- See Also:
for format syntax and variables.
-
getResponseLogMessage
public java.lang.String getResponseLogMessage(Response response, int duration)
Format an access log entry. If the log template property isn't provided, then a default IIS like format is used.- Parameters:
response
- The response to log.duration
- The call duration.- Returns:
- The formatted log entry.
-
isDebugging
@Deprecated protected boolean isDebugging()
Deprecated.Rely onApplication.isDebugging()
instead.Indicates if the debugging mode is enabled. False by default.- Returns:
- True if the debugging mode is enabled.
-
isIdentityCheck
public boolean isIdentityCheck()
Indicates if the identity check (as specified by RFC1413) is enabled. Default value is false.- Returns:
- True if the identity check is enabled.
-
isLoggable
public boolean isLoggable(Request request)
Indicates if the call should be logged during the processing chain. By default, it tries to match the request URI with thegetLoggableTemplate()
URI template otherwise is returns true.- Parameters:
request
- The request to log.- Returns:
- True if the call should be logged during the processing chain.
-
setDebugging
@Deprecated protected void setDebugging(boolean debugging)
Deprecated.Rely onApplication.setDebugging(boolean)
instead.Indicates if the debugging mode is enabled.- Parameters:
debugging
- True if the debugging mode is enabled.
-
setIdentityCheck
public void setIdentityCheck(boolean identityCheck)
Indicates if the identity check (as specified by RFC1413) is enabled.- Parameters:
identityCheck
- True if the identity check is enabled.
-
setLoggableTemplate
public void setLoggableTemplate(java.lang.String loggableTemplateRef)
Sets the URI template of loggable resource references.- Parameters:
loggableTemplateRef
- The URI template of loggable resource references.- See Also:
setLoggableTemplate(Template)
-
setLoggableTemplate
public void setLoggableTemplate(Template loggableTemplate)
Sets the URI template of loggable resource references.- Parameters:
loggableTemplate
- The URI template of loggable resource references.
-
setLoggerName
public void setLoggerName(java.lang.String name)
Sets the name of the JDK's logger to use when logging access calls.- Parameters:
name
- The name of the JDK's logger to use when logging access calls.
-
setLogPropertiesRef
public void setLogPropertiesRef(Reference logPropertiesRef)
Sets the URI reference of the log properties.- Parameters:
logPropertiesRef
- The URI reference of the log properties.
-
setLogPropertiesRef
public void setLogPropertiesRef(java.lang.String logPropertiesUri)
Sets the URI reference of the log properties.- Parameters:
logPropertiesUri
- The URI reference of the log properties.
-
setResponseLogFormat
public void setResponseLogFormat(java.lang.String responseLogFormat)
Sets the format to use when logging responses. The default format matches the one of IIS 6.- Parameters:
responseLogFormat
- The format to use when logging responses.- See Also:
for format syntax and variables.
-
start
public void start() throws java.lang.Exception
Starts the log service by attempting to read the log properties if thegetLogPropertiesRef()
returns a non null URI reference.
-
-