001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.geronimo.jetty.requestlog; 019 020 import org.apache.geronimo.gbean.GBeanInfo; 021 import org.apache.geronimo.gbean.GBeanInfoBuilder; 022 import org.apache.geronimo.gbean.GBeanLifecycle; 023 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 024 import org.apache.geronimo.jetty.JettyContainer; 025 import org.apache.geronimo.system.serverinfo.ServerInfo; 026 027 /** 028 * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $ 029 */ 030 public class NCSARequestLog implements GBeanLifecycle, JettyRequestLog { 031 private final JettyContainer container; 032 private final ServerInfo serverInfo; 033 private final org.mortbay.http.NCSARequestLog requestLog; 034 private boolean preferProxiedForAddress; 035 private String filename; 036 037 public NCSARequestLog(JettyContainer container, ServerInfo serverInfo) { 038 this.container = container; 039 this.serverInfo = serverInfo; 040 requestLog = new org.mortbay.http.NCSARequestLog(); 041 } 042 043 public void setFilename(String filename) { 044 this.filename = filename; 045 } 046 047 public String getFilename() { 048 return filename; 049 } 050 051 public void setLogDateFormat(String format) { 052 requestLog.setLogDateFormat(format); 053 } 054 055 public String getLogDateFormat() { 056 return requestLog.getLogDateFormat(); 057 } 058 059 public void setLogTimeZone(String tz) { 060 requestLog.setLogTimeZone(tz); 061 } 062 063 public String getLogTimeZone() { 064 return requestLog.getLogTimeZone(); 065 } 066 067 public int getRetainDays() { 068 return requestLog.getRetainDays(); 069 } 070 071 public void setRetainDays(int retainDays) { 072 requestLog.setRetainDays(retainDays); 073 } 074 075 public boolean isExtended() { 076 return requestLog.isExtended(); 077 } 078 079 public void setExtended(boolean e) { 080 requestLog.setExtended(e); 081 } 082 083 public boolean isAppend() { 084 return requestLog.isAppend(); 085 } 086 087 public void setAppend(boolean a) { 088 requestLog.setAppend(a); 089 } 090 091 public void setIgnorePaths(String[] ignorePaths) { 092 requestLog.setIgnorePaths(ignorePaths); 093 } 094 095 public String[] getIgnorePaths() { 096 return requestLog.getIgnorePaths(); 097 } 098 099 public void setPreferProxiedForAddress(boolean value) { 100 this.preferProxiedForAddress = value; 101 requestLog.setPreferProxiedForAddress(value); 102 } 103 104 public boolean isPreferProxiedForAddress() { 105 return preferProxiedForAddress; 106 } 107 108 public String getAbsoluteFilePath() { 109 return requestLog == null ? null : requestLog.getDatedFilename(); 110 } 111 112 public void doStart() throws Exception { 113 requestLog.setFilename(serverInfo.resolveServerPath(filename)); 114 container.setRequestLog(requestLog); 115 requestLog.start(); 116 } 117 118 public void doStop() throws Exception { 119 requestLog.stop(); 120 container.setRequestLog(null); 121 } 122 123 public void doFail() { 124 container.setRequestLog(null); 125 requestLog.stop(); 126 } 127 128 public static final GBeanInfo GBEAN_INFO; 129 130 static { 131 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("NCSA Request Log", NCSARequestLog.class); 132 infoFactory.addReference("JettyContainer", JettyContainer.class, NameFactory.GERONIMO_SERVICE); 133 infoFactory.addReference("ServerInfo", ServerInfo.class, NameFactory.GERONIMO_SERVICE); 134 135 infoFactory.addInterface(JettyRequestLog.class, new String[]{"filename", "logDateFormat", "logTimeZone", 136 "retainDays", "extended", "append", "ignorePaths", "preferProxiedForAddress", }); 137 138 infoFactory.setConstructor(new String[]{"JettyContainer", "ServerInfo"}); 139 GBEAN_INFO = infoFactory.getBeanInfo(); 140 } 141 142 public static GBeanInfo getGBeanInfo() { 143 return GBEAN_INFO; 144 } 145 }