001: /*
002: * Copyright 2005-2007 Noelios Consulting.
003: *
004: * The contents of this file are subject to the terms of the Common Development
005: * and Distribution License (the "License"). You may not use this file except in
006: * compliance with the License.
007: *
008: * You can obtain a copy of the license at
009: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
010: * language governing permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL HEADER in each file and
013: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
014: * applicable, add the following below this CDDL HEADER, with the fields
015: * enclosed by brackets "[]" replaced with your own identifying information:
016: * Portions Copyright [yyyy] [name of copyright owner]
017: */
018:
019: package org.restlet.service;
020:
021: /**
022: * Service providing access logging service. The implementation is fully based
023: * on the standard logging mechanism introduced in JDK 1.4.<br>
024: * <br>
025: * The default access log format follows the <a
026: * href="http://www.w3.org/TR/WD-logfile.html"> W3C Extended Log File Format</a>
027: * with the following fields used: <br/>
028: * <ol>
029: * <li>Date (YYYY-MM-DD)</li>
030: * <li>Time (HH:MM:SS)</li>
031: * <li>Client address (IP)</li>
032: * <li>Remote user identifier (see RFC 1413)</li>
033: * <li>Server address (IP)</li>
034: * <li>Server port</li>
035: * <li>Method (GET|POST|...)</li>
036: * <li>Resource reference path (including the leading slash)</li>
037: * <li>Resource reference query (excluding the leading question mark)</li>
038: * <li>Response status code</li>
039: * <li>Number of bytes sent</li>
040: * <li>Number of bytes received</li>
041: * <li>Time to serve the request (in milliseconds)</li>
042: * <li>Host reference</li>
043: * <li>Client agent name</li>
044: * <li>Referrer reference</li>
045: * </ol>
046: * <br>
047: * <br>
048: * If you use <a href="http://www.analog.cx">Analog</a> to generate your log
049: * reports, and if you use the default log format, then you can simply specify
050: * this string as a value of the LOGFORMAT command:
051: * (%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)<br/>
052: * <br>
053: * For custom access log format, see the syntax to use and the list of available
054: * variable names in {@link org.restlet.util.Template}. <br>
055: *
056: * @see <a href="http://www.restlet.org/documentation/1.0/tutorial#part07">Tutorial: Access
057: * logging</a>
058: * @see <a
059: * href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/logging/package-summary.html">java.util.logging</a>
060: * @author Jerome Louvel (contact@noelios.com)
061: */
062: public class LogService {
063: /** Indicates if the service has been enabled. */
064: private boolean enabled;
065:
066: /** The access logger name. */
067: private String loggerName;
068:
069: /** The log entry format. */
070: private String logFormat;
071:
072: /** Indicates if the identity check (as specified by RFC1413) is enabled. */
073: private boolean identityCheck;
074:
075: /**
076: * Constructor.
077: *
078: * @param enabled
079: * True if the service has been enabled.
080: */
081: public LogService(boolean enabled) {
082: this .loggerName = null;
083: this .enabled = enabled;
084: this .logFormat = null;
085: this .identityCheck = false;
086: }
087:
088: /**
089: * Returns the format used.
090: *
091: * @return The format used, or null if the default one is used.
092: * @see org.restlet.util.Template for format syntax and variables.
093: */
094: public String getLogFormat() {
095: return this .logFormat;
096: }
097:
098: /**
099: * Returns the name of the JDK's logger to use when logging calls.
100: *
101: * @return The name of the JDK's logger to use when logging calls.
102: */
103: public String getLoggerName() {
104: return this .loggerName;
105: }
106:
107: /**
108: * Indicates if the service should be enabled.
109: *
110: * @return True if the service should be enabled.
111: */
112: public boolean isEnabled() {
113: return this .enabled;
114: }
115:
116: /**
117: * Indicates if the identity check (as specified by RFC1413) is enabled.
118: * Default value is false.
119: *
120: * @return True if the identity check is enabled.
121: */
122: public boolean isIdentityCheck() {
123: return this .identityCheck;
124: }
125:
126: /**
127: * Sets the format to use when logging calls. The default format matches the
128: * one of IIS 6.
129: *
130: * @param format
131: * The format to use when loggin calls.
132: * @see org.restlet.util.Template for format syntax and variables.
133: */
134: public void setLogFormat(String format) {
135: this .logFormat = format;
136: }
137:
138: /**
139: * Sets the name of the JDK's logger to use when logging calls.
140: *
141: * @param name
142: * The name of the JDK's logger to use when logging calls.
143: */
144: public void setLoggerName(String name) {
145: this .loggerName = name;
146: }
147:
148: /**
149: * Indicates if the service should be enabled.
150: *
151: * @param enabled
152: * True if the service should be enabled.
153: */
154: public void setEnabled(boolean enabled) {
155: this .enabled = enabled;
156: }
157:
158: /**
159: * Indicates if the identity check (as specified by RFC1413) is enabled.
160: *
161: * @param enabled
162: * True if the identity check is enabled.
163: */
164: public void setIdentityCheck(boolean enabled) {
165: this.identityCheck = enabled;
166: }
167:
168: }
|