001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.server.log;
031:
032: import com.caucho.config.Config;
033: import com.caucho.config.ConfigException;
034: import com.caucho.config.program.ContainerProgram;
035: import com.caucho.loader.Environment;
036: import com.caucho.vfs.Path;
037:
038: import javax.annotation.*;
039: import javax.servlet.ServletContext;
040: import javax.servlet.ServletException;
041: import javax.servlet.http.HttpServletRequest;
042: import javax.servlet.http.HttpServletResponse;
043: import java.io.IOException;
044: import java.util.logging.Logger;
045:
046: /**
047: * Represents an log of every top-level request to the server.
048: */
049: abstract public class AbstractAccessLog {
050: protected static final Logger log = Logger
051: .getLogger(AbstractAccessLog.class.getName());
052:
053: protected Path _path;
054:
055: protected String _pathFormat;
056:
057: private AccessLogAdmin _admin;
058:
059: protected AbstractAccessLog() {
060: _admin = new AccessLogAdmin(this );
061:
062: Environment.addCloseListener(this );
063: }
064:
065: /**
066: * Returns the access-log's path.
067: */
068: public Path getPath() {
069: return _path;
070: }
071:
072: /**
073: * Sets the access-log's path.
074: */
075: public void setPath(Path path) {
076: _path = path;
077: }
078:
079: /**
080: * Returns the formatted path
081: */
082: public String getPathFormat() {
083: return _pathFormat;
084: }
085:
086: /**
087: * Sets the formatted path.
088: */
089: public void setPathFormat(String pathFormat) throws ConfigException {
090: _pathFormat = pathFormat;
091: }
092:
093: /**
094: * Sets the access-log's path (backwards compatibility).
095: */
096: public void setId(Path path) {
097: setPath(path);
098: }
099:
100: public void addInit(ContainerProgram init) {
101: init.configure(this );
102: Config.init(this );
103: }
104:
105: /**
106: * Initialize the log.
107: */
108: public void init() throws ServletException, IOException {
109: }
110:
111: /**
112: * Logs a request using the current format.
113: *
114: * @param request the servlet request.
115: * @param response the servlet response.
116: */
117: public abstract void log(HttpServletRequest request,
118: HttpServletResponse response, ServletContext application)
119: throws IOException;
120:
121: /**
122: * Flushes the log.
123: */
124: public void flush() {
125: }
126:
127: /**
128: * Cleanup the log.
129: */
130: public void destroy() throws IOException {
131: flush();
132: }
133: }
|