You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by am...@apache.org on 2005/11/16 01:13:56 UTC
svn commit: r344487 - in /geronimo/trunk:
applications/console-standard/src/java/org/apache/geronimo/console/logmanager/
applications/console-standard/src/webapp/WEB-INF/view/webaccesslogmanager/
modules/assembly/src/plan/ modules/jetty/src/java/org/ap...
Author: ammulder
Date: Tue Nov 15 16:13:46 2005
New Revision: 344487
URL: http://svn.apache.org/viewcvs?rev=344487&view=rev
Log:
Update the web access log portlet
- handles date ranges appropriately (thanks to Joe Bohn for patch,
GERONIMO-1068)
- handles multiple web containers pretty much correctly (excepting only
the first time you submit for a different container that has more
than one log in use)
Modified:
geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java
geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/webaccesslogmanager/view.jsp
geronimo/trunk/modules/assembly/src/plan/j2ee-jetty-plan.xml
geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyManagerImpl.java
geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/requestlog/JettyLogManagerImpl.java
geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebAccessLog.java
geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebManager.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatLogManagerImpl.java
geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatManagerImpl.java
Modified: geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java?rev=344487&r1=344486&r2=344487&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java (original)
+++ geronimo/trunk/applications/console-standard/src/java/org/apache/geronimo/console/logmanager/WebAccessLogViewerPortlet.java Tue Nov 15 16:13:46 2005
@@ -19,13 +19,18 @@
import java.io.IOException;
import java.util.Calendar;
+import java.util.Map;
+import java.util.LinkedHashMap;
import javax.portlet.*;
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
import org.apache.geronimo.console.BasePortlet;
import org.apache.geronimo.console.util.PortletManager;
-import org.apache.geronimo.management.geronimo.WebContainer;
import org.apache.geronimo.management.geronimo.WebAccessLog;
+import org.apache.geronimo.management.geronimo.WebManager;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -47,92 +52,143 @@
return;
}
- String[] names = PortletManager.getWebManagerNames(renderRequest); //todo: handle multiple
- if (names != null) {
- String managerName = names[0]; //todo: handle multiple
- String[] containers = PortletManager.getWebContainerNames(renderRequest, managerName); //todo: handle multiple
- if (containers != null) {
- String containerName = containers[0]; //todo: handle multiple
- WebAccessLog log = PortletManager.getWebAccessLog(renderRequest, managerName, containerName);
-
- String action = renderRequest.getParameter("action");
- if ("refresh".equals(action)) {
- //todo: currently refreshes on every request; that's pretty slow.
+ String[] names = PortletManager.getWebManagerNames(renderRequest);
+
+ //todo: new
+ Map products = new LinkedHashMap();
+ String chosen = renderRequest.getParameter("selectedContainer");
+ if(chosen != null) { // Carry on to render the results with the right selection
+ renderRequest.setAttribute("selectedContainer", chosen);
+ }
+ WebAccessLog chosenLog = null;
+ if(names != null) {
+ for (int i = 0; i < names.length; i++) {
+ String webManagerName = names[i];
+ WebManager manager = (WebManager) PortletManager.getManagedBean(renderRequest, webManagerName);
+ String[] containers = PortletManager.getWebContainerNames(renderRequest, webManagerName);
+ if (containers != null) {
+ for (int j = 0; j < containers.length; j++) {
+ String containerName = containers[j];
+ String combined = webManagerName+"%"+containerName;
+ if(containers.length == 1) {
+ products.put(manager.getProductName(), combined);
+ } else {
+ try {
+ ObjectName containerON = ObjectName.getInstance(containerName);
+ products.put(manager.getProductName()+" ("+containerON.getKeyProperty(NameFactory.J2EE_NAME)+")", combined);
+ } catch (MalformedObjectNameException e) {
+ log.error("Unable to parse ObjectName", e);
+ }
+ }
+ if(chosenLog == null) { // will pick the correct match, or the first if no selection is specified
+ if(chosen == null || chosen.equals(combined)) {
+ chosenLog = PortletManager.getWebAccessLog(renderRequest, webManagerName, containerName);
+ }
+ }
+ }
+ } else {
+ log.error("No web containers found for manager "+manager.getProductName());
}
+ }
+ } else {
+ log.error("No web managers found!");
+ }
+ renderRequest.setAttribute("webContainers", products);
+ final String[] logNames = chosenLog.getLogNames();
+ renderRequest.setAttribute("webLogs", logNames);
+ String logToSearch = renderRequest.getParameter("selectedLog");
+ if(logToSearch == null) {
+ logToSearch = logNames[0];
+ } else { //what if the log options for Jetty were showing, but the user picked Tomcat to search? todo: fix this with some AJAX to repopulate the form when container is changed
+ boolean found = false;
+ for (int i = 0; i < logNames.length; i++) {
+ String test = logNames[i];
+ if(test.equals(logToSearch)) {
+ found = true;
+ break;
+ }
+ }
+ if(!found) { // Must has been for the other container -- make it work.
+ logToSearch = logNames[0];
+ }
+ }
+ String action = renderRequest.getParameter("action");
+ if ("refresh".equals(action)) {
+ //todo: currently refreshes on every request; that's pretty slow.
+ }
- //todo: completely revamp this argument processing
- String startDate = (String) renderRequest.getParameter("startDate");
- String startMonth = (String) renderRequest.getParameter("startMonth");
- String startYear = (String) renderRequest.getParameter("startYear");
- String endDate = (String) renderRequest.getParameter("endDate");
- String endMonth = (String) renderRequest.getParameter("endMonth");
- String endYear = (String) renderRequest.getParameter("endYear");
-
- Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
- // If not all dates were passed we assume than no fields were passed and just
- // filter on the current date.
- if (startDate == null || startMonth == null || startYear == null
- || endDate == null || endMonth == null || endYear == null) {
- // just keep the month date and year
- cal1.set(Calendar.MILLISECOND, 0);
- cal1.set(Calendar.MINUTE, 0);
- cal1.set(Calendar.SECOND, 0);
- cal1.clear(Calendar.HOUR_OF_DAY);
- cal2.setTime(cal1.getTime());
- cal2.add(Calendar.DAY_OF_YEAR, 1);
-
- WebAccessLog.SearchResults matchingItems = log.getMatchingItems(log.getLogFileNames()[0], //todo: handle multiple
- null, null, null, null, cal1.getTime(), cal2.getTime(), null, null);
- renderRequest.setAttribute("logs", matchingItems.getResults());
- renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
- } else {
- int sdt = Integer.parseInt(startDate),
- smnth = Integer.parseInt(startMonth),
- syr = Integer.parseInt(startYear),
- edt = Integer.parseInt(endDate),
- emnth = Integer.parseInt(endMonth),
- eyr = Integer.parseInt(endYear);
- boolean ignoreDates = renderRequest.getParameter("ignoreDates") == null;
- String requestHost = (String) renderRequest.getParameter("requestHost");
- String authUser = (String) renderRequest.getParameter("authUser");
- String requestMethod = (String) renderRequest.getParameter("requestMethod");
- String requestedURI = (String) renderRequest.getParameter("requestedURI");
- if (ignoreDates) {
- cal1.clear();
- cal2.clear();
- cal1.set(Calendar.DATE, sdt);
- cal1.set(Calendar.MONTH, smnth);
- cal1.set(Calendar.YEAR, syr);
- cal2.set(Calendar.DATE, edt);
- cal2.set(Calendar.MONTH, emnth);
- cal2.set(Calendar.YEAR, eyr);
- WebAccessLog.SearchResults matchingItems = log.getMatchingItems(log.getLogFileNames()[0], //todo: handle multiple
- requestHost, authUser, requestMethod, requestedURI, cal1.getTime(), cal2.getTime(), null, null);
- renderRequest.setAttribute("logs", matchingItems.getResults());
- renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
- } else {
- WebAccessLog.SearchResults matchingItems = log.getMatchingItems(log.getLogFileNames()[0], //todo: handle multiple
- requestHost, authUser, requestMethod, requestedURI, null, null, null, null);
- renderRequest.setAttribute("logs", matchingItems.getResults());
- renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
- }
- renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
- renderRequest.setAttribute("requestHost", requestHost);
- renderRequest.setAttribute("authUser", authUser);
- renderRequest.setAttribute("requestMethod", requestMethod);
- renderRequest.setAttribute("requestedURI", requestedURI);
- }
- renderRequest.setAttribute("toDate", cal2.getTime());
- renderRequest.setAttribute("fromDate", cal1.getTime());
- searchView.include(renderRequest, renderRespose);
+ //todo: completely revamp this argument processing
+ String startDate = (String) renderRequest.getParameter("startDate");
+ String startMonth = (String) renderRequest.getParameter("startMonth");
+ String startYear = (String) renderRequest.getParameter("startYear");
+ String endDate = (String) renderRequest.getParameter("endDate");
+ String endMonth = (String) renderRequest.getParameter("endMonth");
+ String endYear = (String) renderRequest.getParameter("endYear");
+
+ Calendar cal1 = Calendar.getInstance(), cal2 = Calendar.getInstance();
+ // If not all dates were passed we assume than no fields were passed and just
+ // filter on the current date.
+ if (startDate == null || startMonth == null || startYear == null
+ || endDate == null || endMonth == null || endYear == null) {
+ // just keep the month date and year
+ cal1.set(Calendar.MILLISECOND, 0);
+ cal1.set(Calendar.MINUTE, 0);
+ cal1.set(Calendar.SECOND, 0);
+ cal1.set(Calendar.HOUR_OF_DAY, 0);
+
+ cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
+ cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
+ cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
+ cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
+
+ WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
+ null, null, null, null, cal1.getTime(), cal2.getTime(), null, null);
+ renderRequest.setAttribute("logs", matchingItems.getResults());
+ renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
+ } else {
+ cal1.clear();
+ cal2.clear();
+ // get the requested start date (defaults to 00:00:00:000 for time
+ cal1.set(Calendar.DATE, Integer.parseInt(startDate));
+ cal1.set(Calendar.MONTH, Integer.parseInt(startMonth));
+ cal1.set(Calendar.YEAR, Integer.parseInt(startYear));
+ // get the requested end date - Note: must set time to end of day
+ cal2.set(Calendar.DATE, Integer.parseInt(endDate));
+ cal2.set(Calendar.MONTH, Integer.parseInt(endMonth));
+ cal2.set(Calendar.YEAR, Integer.parseInt(endYear));
+ cal2.set(Calendar.HOUR_OF_DAY, cal2.getMaximum(Calendar.HOUR_OF_DAY));
+ cal2.set(Calendar.MINUTE, cal2.getMaximum(Calendar.MINUTE));
+ cal2.set(Calendar.SECOND, cal2.getMaximum(Calendar.SECOND));
+ cal2.set(Calendar.MILLISECOND, cal2.getMaximum(Calendar.MILLISECOND));
+ // Get other search criteria
+ String requestHost = (String) renderRequest.getParameter("requestHost");
+ String authUser = (String) renderRequest.getParameter("authUser");
+ String requestMethod = (String) renderRequest.getParameter("requestMethod");
+ String requestedURI = (String) renderRequest.getParameter("requestedURI");
+ boolean ignoreDates = renderRequest.getParameter("ignoreDates") != null;
+ if (ignoreDates) {
+ WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
+ requestHost, authUser, requestMethod, requestedURI, null, null, null, null);
+ renderRequest.setAttribute("logs", matchingItems.getResults());
+ renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
} else {
- log.error("No web containers found");
+ WebAccessLog.SearchResults matchingItems = chosenLog.getMatchingItems(logToSearch,
+ requestHost, authUser, requestMethod, requestedURI, cal1.getTime(), cal2.getTime(), null, null);
+ renderRequest.setAttribute("logs", matchingItems.getResults());
+ renderRequest.setAttribute("logLength", new Integer(matchingItems.getLineCount()));
}
- } else {
- log.error("No web managers found");
+ if (ignoreDates) renderRequest.setAttribute("ignoreDates", new Boolean(ignoreDates));
+ renderRequest.setAttribute("requestHost", requestHost);
+ renderRequest.setAttribute("authUser", authUser);
+ renderRequest.setAttribute("requestMethod", requestMethod);
+ renderRequest.setAttribute("requestedURI", requestedURI);
+
}
+ renderRequest.setAttribute("toDate", cal2.getTime());
+ renderRequest.setAttribute("fromDate", cal1.getTime());
+ searchView.include(renderRequest, renderRespose);
}
public void init(PortletConfig portletConfig) throws PortletException {
Modified: geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/webaccesslogmanager/view.jsp
URL: http://svn.apache.org/viewcvs/geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/webaccesslogmanager/view.jsp?rev=344487&r1=344486&r2=344487&view=diff
==============================================================================
--- geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/webaccesslogmanager/view.jsp (original)
+++ geronimo/trunk/applications/console-standard/src/webapp/WEB-INF/view/webaccesslogmanager/view.jsp Tue Nov 15 16:13:46 2005
@@ -50,11 +50,57 @@
<form action="<portlet:renderURL/>" name="<portlet:namespace/>searchForm" method="post">
<b>Filter results:</b>
<table width="680">
+ <c:choose>
+ <c:when test="${fn:length(webContainers) > 1}">
+ <tr>
+ <td colspan="4" class="DarkBackground"><b>Container:</b></td>
+ </tr>
+ <tr>
+ <td>Search Web Container:</td>
+ <td>
+ <select name="selectedContainer">
+ <c:forEach var="webContainer" items="${webContainers}">
+ <option value="${webContainer.value}"<c:if test="${webContainer.value eq selectedContainer}"> selected</c:if>>${webContainer.key}</option>
+ </c:forEach>
+ </select>
+ </td>
+ </tr>
+ </c:when>
+ <c:otherwise>
+ <c:forEach var="webContainer" items="${webContainers}">
+ <tr><td><input type="hidden" name="selectedContainer" value="${webContainer.value}" /></td></tr>
+ </c:forEach>
+ </c:otherwise>
+ </c:choose>
+ <%-- todo: When the user changes the selected container, we need to change the log selection options!!!
+ need some AJAX here. :) --%>
+ <c:choose>
+ <c:when test="${fn:length(webLogs) > 1}">
+ <tr>
+ <td colspan="4" class="DarkBackground"><b>Log:</b></td>
+ </tr>
+ <tr>
+ <td>Search Web Log:</td>
+ <td>
+ <select name="selectedLog">
+ <c:forEach var="webLog" items="${webLogs}">
+ <option<c:if test="${webLog eq selectedLog}"> selected</c:if>>${webLog}</option>
+ </c:forEach>
+ </select>
+ </td>
+ </tr>
+ </c:when>
+ <c:otherwise>
+ <c:forEach var="webLog" items="${webLogs}">
+ <tr><td><input type="hidden" name="selectedLog" value="${webLog}" /></td></tr>
+ </c:forEach>
+ </c:otherwise>
+ </c:choose>
<tr>
<td colspan="4" class="DarkBackground"><b>Date:</b></td>
</tr>
<tr>
- <td>From:</td>
+ <td>From:</td>
<td>
<select name="startMonth" onchange="<portlet:namespace/>loadDates('startMonth','startDate','startYear');">
<option value="0">January</option><option value="1">February</option>
@@ -102,7 +148,7 @@
<tr>
<td>Ignore Dates:</td>
<td>
- <input type="checkbox" name="ignoreDates" <c:if test="${ignoreDate}"> checked</c:if>/>
+ <input type="checkbox" name="ignoreDates" <c:if test="${ignoreDates}"> checked</c:if>/>
</td>
</tr>
<tr>
@@ -144,7 +190,7 @@
<c:when test="${logs != null && fn:length(logs) > 0}">
<table>
<tr>
- <td><b>Found ${fn:length(logs)} matches in logfile.</b></td>
+ <td><b>Found ${fn:length(logs)} matches in logfile (${logLength} lines searched).</b></td>
</tr>
<c:forEach var="line" items="${logs}">
<tr>
Modified: geronimo/trunk/modules/assembly/src/plan/j2ee-jetty-plan.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/src/plan/j2ee-jetty-plan.xml?rev=344487&r1=344486&r2=344487&view=diff
==============================================================================
--- geronimo/trunk/modules/assembly/src/plan/j2ee-jetty-plan.xml (original)
+++ geronimo/trunk/modules/assembly/src/plan/j2ee-jetty-plan.xml Tue Nov 15 16:13:46 2005
@@ -38,6 +38,10 @@
<gbean name="JettyWebManager" class="org.apache.geronimo.jetty.JettyManagerImpl"/>
<gbean name="JettyAccessLogManager" class="org.apache.geronimo.jetty.requestlog.JettyLogManagerImpl">
+ <reference name="ServerInfo">
+ <module>org/apache/geronimo/System</module>
+ <name>ServerInfo</name>
+ </reference>
<references name="LogGBeans">
<pattern>
<!-- This is lame and should be replaced by an interface reference -->
Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyManagerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyManagerImpl.java?rev=344487&r1=344486&r2=344487&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyManagerImpl.java (original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyManagerImpl.java Tue Nov 15 16:13:46 2005
@@ -55,6 +55,10 @@
this.kernel = kernel;
}
+ public String getProductName() {
+ return "Jetty";
+ }
+
/**
* Creates a new connector, and returns the ObjectName for it. Note that
* the connector may well require further customization before being fully
Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/requestlog/JettyLogManagerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/requestlog/JettyLogManagerImpl.java?rev=344487&r1=344486&r2=344487&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/requestlog/JettyLogManagerImpl.java (original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/requestlog/JettyLogManagerImpl.java Tue Nov 15 16:13:46 2005
@@ -18,6 +18,7 @@
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.system.serverinfo.ServerInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -25,6 +26,7 @@
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.File;
+import java.io.FilenameFilter;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.MappedByteBuffer;
@@ -40,6 +42,14 @@
*/
public class JettyLogManagerImpl implements JettyLogManager {
private final static Log log = LogFactory.getLog(JettyLogManagerImpl.class);
+
+ // Pattern that matches the date in the logfile name
+ private final static Pattern FILENAME_DATE_PATTERN = Pattern.compile("[-_ /.](((19|20)\\d\\d)[-_ /.](0[1-9]|1[012])[-_ /.](0[1-9]|[12][0-9]|3[01]))");
+ private final static int GROUP_FILENAME_FULL_DATE = 1;
+ private final static int GROUP_FILENAME_YEAR = 2;
+ private final static int GROUP_FILENAME_MONTH = 4;
+ private final static int GROUP_FILENAME_DAY = 5;
+
// Pattern that matches a single line (used to calculate line numbers)
private final static Pattern FULL_LINE_PATTERN = Pattern.compile("^.*", Pattern.MULTILINE);
private final static Pattern ACCESS_LOG_PATTERN = Pattern.compile("(\\S*) (\\S*) (\\S*) \\[(.*)\\] \\\"(\\S*) (\\S*).*?\\\" (\\S*) (\\S*).*");
@@ -51,109 +61,190 @@
private final static int GROUP_RESPONSE_CODE = 7;
private final static int GROUP_RESPONSE_LENGTH = 8;
private final static String ACCESS_LOG_DATE_FORMAT = "dd/MMM/yyyy:HH:mm:ss ZZZZ";
- private Collection logGbeans;
+ private final static String LOG_FILE_NAME_FORMAT = "yyyy_MM_dd";
+ private final Collection logGbeans;
+ private final ServerInfo serverInfo;
- public JettyLogManagerImpl(Collection logGbeans) {
+ public JettyLogManagerImpl(ServerInfo serverInfo, Collection logGbeans) {
+ this.serverInfo = serverInfo;
this.logGbeans = logGbeans;
}
- public String[] getLogFileNames() {
- List files = new ArrayList();
+ /**
+ * Gets the name of all logs used by this system. Typically there
+ * is only one, but specialized cases may use more.
+ *
+ * @return An array of all log names
+ *
+ */
+ public String[] getLogNames() {
+ List logNames = new ArrayList();
for (Iterator it = logGbeans.iterator(); it.hasNext();) {
- JettyRequestLog log = (JettyRequestLog) it.next();
- if(log.getFilename() != null) {
- files.add(log.getFilename());
+ JettyRequestLog jettyLog = (JettyRequestLog) it.next();
+ if(jettyLog.getFilename() != null) {
+ logNames.add(jettyLog.getFilename());
}
}
- return (String[]) files.toArray(new String[files.size()]);
+ return (String[]) logNames.toArray(new String[logNames.size()]);
}
- public SearchResults getMatchingItems(String logFile, String host, String user, String method, String uri,
- Date startDate, Date endDate, Integer skipResults, Integer maxResults) {
- File log = null;
- for (Iterator it = logGbeans.iterator(); it.hasNext();) {
- JettyRequestLog logger = (JettyRequestLog) it.next();
- if(logger.getFilename() != null && logger.getFilename().equals(logFile)) {
- log = new File(logger.getAbsoluteFilePath());
- break;
+ /**
+ * Gets the names of all log files for this log name.
+ *
+ * @param logName The name of the log for which to return the specific file names.
+ *
+ * @return An array of log file names
+ *
+ */
+ public String[] getLogFileNames(String logName) {
+ List names = new ArrayList();
+
+ // Find all the files for this logName
+ File[] logFiles = getLogFiles(logName);
+
+ if (logFiles !=null) {
+ for (int i = 0; i < logFiles.length; i++) {
+ names.add(logFiles[i].getName());
}
}
- if(log == null) {
- throw new IllegalArgumentException("Unknown log file '"+logFile+"'");
- }
+ return (String[]) names.toArray(new String[names.size()]);
+ }
+
+ /**
+ * Gets the name of all log files used by this log. Typically there
+ * is only one, but specialized cases may use more.
+ *
+ * @param logName The name of the log for which to return the specific files.
+ *
+ * @return An array of all log file names
+ *
+ */
+ private File[] getLogFiles(String logName) {
+ File[] logFiles = null;
+
+ try {
+ String fileNamePattern = logName;
+ if (fileNamePattern.indexOf(File.separator) > -1) {
+ fileNamePattern = fileNamePattern.substring(fileNamePattern.lastIndexOf(File.separator) + 1);
+ }
- return search(log, host, user, method, uri, startDate, endDate, skipResults, maxResults);
+ String logFile = serverInfo.resolvePath(logName);
+
+ File parent = new File(logFile).getParentFile();
+
+ if (parent != null) {
+ logFiles = parent.listFiles(new PatternFilenameFilter(fileNamePattern));
+ }
+ } catch (Exception e) {
+ log.error("Exception attempting to locate Jetty log files: "+e);
+ logFiles = new File[0];
+ e.printStackTrace();
+ }
+ return logFiles;
}
- private SearchResults search(File file, String host, String user, String method, String uri, Date startDate,
- Date endDate, Integer skipResults, Integer maxResults) {
+ /**
+ * Searches the log for records matching the specified parameters. The
+ * maximum results returned will be the lesser of 1000 and the
+ * provided maxResults argument.
+ *
+ * @see #MAX_SEARCH_RESULTS
+ */
+ public SearchResults getMatchingItems(String logName, String host, String user, String method, String uri, Date startDate,
+ Date endDate, Integer skipResults, Integer maxResults) {
+
// Clean up the arguments so we know what we've really got
if(host != null && host.equals("")) host = null;
if(user != null && user.equals("")) user = null;
if(method != null && method.equals("")) method = null;
if(uri != null && uri.equals("")) uri = null;
- // Do the search
+
+ long start = startDate == null ? 0 : startDate.getTime();
+ long end = endDate == null ? 0 : endDate.getTime();
+
List list = new LinkedList();
boolean capped = false;
- int lineCount = 0;
- try {
- RandomAccessFile raf = new RandomAccessFile(file, "r");
- FileChannel fc = raf.getChannel();
- MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
- CharBuffer cb = Charset.forName("US-ASCII").decode(bb); //todo: does Jetty use a different charset on a foreign PC?
- Matcher lines = FULL_LINE_PATTERN.matcher(cb);
- Matcher target = ACCESS_LOG_PATTERN.matcher("");
- long start = startDate == null ? 0 : startDate.getTime();
- long end = endDate == null ? 0 : endDate.getTime();
- SimpleDateFormat format = (start == 0 && end == 0) ? null : new SimpleDateFormat(ACCESS_LOG_DATE_FORMAT);
- int max = maxResults == null ? MAX_SEARCH_RESULTS : Math.min(maxResults.intValue(), MAX_SEARCH_RESULTS);
- while(lines.find()) {
- ++lineCount;
- if(capped) {
- continue;
- }
- CharSequence line = cb.subSequence(lines.start(), lines.end());
- target.reset(line);
- if(target.find()) {
- if(host != null && !host.equals(target.group(GROUP_HOST))) {
- continue;
- }
- if(user != null && !user.equals(target.group(GROUP_USER))) {
- continue;
- }
- if(method != null && !method.equals(target.group(GROUP_METHOD))) {
- continue;
- }
- if(uri != null && !target.group(GROUP_URI).startsWith(uri)) {
- continue;
- }
- if(format != null) {
- try {
- long entry = format.parse(target.group(GROUP_DATE)).getTime();
- if(start > entry) {
+ int lineCount = 0, fileCount = 0;
+
+ // Find all the files for this logName
+ File logFiles[] = getLogFiles(logName);
+
+ if (logFiles !=null) {
+ for (int i = 0; i < logFiles.length; i++) {
+ fileCount = 0;
+ try {
+ // Obtain the date for the current log file
+ String fileName = logFiles[i].getName();
+ Matcher fileDate = FILENAME_DATE_PATTERN.matcher(fileName);
+ fileDate.find();
+ SimpleDateFormat simpleFileDate = new SimpleDateFormat(LOG_FILE_NAME_FORMAT);
+ long logFileTime = simpleFileDate.parse(fileDate.group(GROUP_FILENAME_FULL_DATE)).getTime();
+
+ // Check if the dates are null (ignore) or fall within the search range
+ if ( (start==0 && end==0)
+ || (start>0 && start<=logFileTime && end>0 && end>=logFileTime)) {
+
+ // It's in the range, so process the file
+ RandomAccessFile raf = new RandomAccessFile(logFiles[i], "r");
+ FileChannel fc = raf.getChannel();
+ MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
+ CharBuffer cb = Charset.forName("US-ASCII").decode(bb); //todo: does Jetty use a different charset on a foreign PC?
+ Matcher lines = FULL_LINE_PATTERN.matcher(cb);
+ Matcher target = ACCESS_LOG_PATTERN.matcher("");
+ SimpleDateFormat format = (start == 0 && end == 0) ? null : new SimpleDateFormat(ACCESS_LOG_DATE_FORMAT);
+ int max = maxResults == null ? MAX_SEARCH_RESULTS : Math.min(maxResults.intValue(), MAX_SEARCH_RESULTS);
+
+ while(lines.find()) {
+ ++lineCount;
+ ++fileCount;
+ if(capped) {
continue;
}
- if(end > 0 && end < entry) {
- continue;
+ CharSequence line = cb.subSequence(lines.start(), lines.end());
+ target.reset(line);
+ if(target.find()) {
+ if(host != null && !host.equals(target.group(GROUP_HOST))) {
+ continue;
+ }
+ if(user != null && !user.equals(target.group(GROUP_USER))) {
+ continue;
+ }
+ if(method != null && !method.equals(target.group(GROUP_METHOD))) {
+ continue;
+ }
+ if(uri != null && !target.group(GROUP_URI).startsWith(uri)) {
+ continue;
+ }
+ if(format != null) {
+ try {
+ long entry = format.parse(target.group(GROUP_DATE)).getTime();
+ if(start > entry) {
+ continue;
+ }
+ if(end > 0 && end < entry) {
+ continue;
+ }
+ } catch (ParseException e) {
+ // can't read the date, guess this record counts.
+ }
+ }
+ if(skipResults != null && skipResults.intValue() > lineCount) {
+ continue;
+ }
+ if(list.size() > max) {
+ capped = true;
+ continue;
+ }
+ list.add(new LogMessage(fileCount,line.toString()));
}
- } catch (ParseException e) {
- // can't read the date, guess this record counts.
}
+ fc.close();
+ raf.close();
}
- if(skipResults != null && skipResults.intValue() > lineCount) {
- continue;
- }
- if(list.size() > max) {
- capped = true;
- continue;
- }
- list.add(new LogMessage(lineCount,line.toString()));
+ } catch (Exception e) {
+ log.error("Unexpected error processing logs", e);
}
}
- fc.close();
- raf.close();
- } catch (Exception e) {
- log.error("Unexpected error processing logs", e);
}
return new SearchResults(lineCount, (LogMessage[]) list.toArray(new LogMessage[list.size()]), capped);
}
@@ -164,52 +255,34 @@
static {
GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Jetty Log Manager", JettyLogManagerImpl.class);
infoFactory.addReference("LogGBeans", JettyRequestLog.class);
+ infoFactory.addReference("ServerInfo", ServerInfo.class, "GBean");
infoFactory.addInterface(JettyLogManager.class);
- infoFactory.setConstructor(new String[]{"LogGBeans"});
+ infoFactory.setConstructor(new String[]{"ServerInfo","LogGBeans"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
-/*
- public static void main(String[] args) {
- String jetty = "127.0.0.1 - - [07/Sep/2005:19:54:41 +0000] \"GET /console/ HTTP/1.1\" 302 0 \"-\" \"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050715 Firefox/1.0.6 SUSE/1.0.6-4.1\" -";
- String tomcat = "127.0.0.1 - - [07/Sep/2005:15:51:18 -0500] \"GET /console/portal/server/server_info HTTP/1.1\" 200 11708";
- SimpleDateFormat format = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss ZZZZ");
- try {
- Pattern p = Pattern.compile("(\\S*) (\\S*) (\\S*) \\[(.*)\\] \\\"(\\S*) (\\S*).*?\\\" (\\S*) (\\S*).*");
- Matcher m = p.matcher(jetty);
- if(m.matches()) {
- System.out.println("Group 1: "+m.group(1)); // client
- System.out.println("Group 2: "+m.group(2)); // ?? server host?
- System.out.println("Group 3: "+m.group(3)); // username
- System.out.println("Group 4: "+format.parse(m.group(4))); // date
- System.out.println("Group 5: "+m.group(5)); // method
- System.out.println("Group 5: "+m.group(6)); // URI
- System.out.println("Group 6: "+m.group(7)); // response code
- System.out.println("Group 7: "+m.group(8)); // response length
- } else {
- System.out.println("No match");
- }
- m = p.matcher(tomcat);
- if(m.matches()) {
- System.out.println("Group 1: "+m.group(1));
- System.out.println("Group 2: "+m.group(2));
- System.out.println("Group 3: "+m.group(3));
- System.out.println("Group 4: "+format.parse(m.group(4)));
- System.out.println("Group 5: "+m.group(5)); // method
- System.out.println("Group 5: "+m.group(6)); // URI
- System.out.println("Group 6: "+m.group(7)); // response code
- System.out.println("Group 7: "+m.group(8)); // response length
- } else {
- System.out.println("No match");
- }
- } catch (ParseException e) {
- e.printStackTrace();
+ /*
+ * Static inner class implementation of java.io.Filename. This will help us
+ * filter for only the files that we are interested in.
+ */
+ static class PatternFilenameFilter implements FilenameFilter {
+ Pattern pattern;
+ //todo: put this pattern in a GBean parameter?
+ PatternFilenameFilter(String fileNamePattern) {
+ fileNamePattern = fileNamePattern.replaceAll("yyyy", "\\\\d{4}");
+ fileNamePattern = fileNamePattern.replaceAll("yy", "\\\\d{2}");
+ fileNamePattern = fileNamePattern.replaceAll("mm", "\\\\d{2}");
+ fileNamePattern = fileNamePattern.replaceAll("dd", "\\\\d{2}");
+ this.pattern = Pattern.compile(fileNamePattern);
+ }
+
+ public boolean accept(File file, String fileName) {
+ return pattern.matcher(fileName).matches();
}
}
-*/
}
Modified: geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebAccessLog.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebAccessLog.java?rev=344487&r1=344486&r2=344487&view=diff
==============================================================================
--- geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebAccessLog.java (original)
+++ geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebAccessLog.java Tue Nov 15 16:13:46 2005
@@ -32,10 +32,24 @@
public final static int MAX_SEARCH_RESULTS = 1000;
/**
- * Gets the name of all log files used by this log system. Typically there
+ * Gets the name of all logs used by this system. Typically there
* is only one, but specialized cases may use more.
+ *
+ * @return An array of all log names
+ *
+ */
+ String[] getLogNames();
+
+ /**
+ * Gets the name of all log files used by this log. Typically there
+ * is only one, but specialized cases may use more.
+ *
+ * @param log The name of the log for which to return the specific file names.
+ *
+ * @return An array of all log file names
+ *
*/
- String[] getLogFileNames();
+ String[] getLogFileNames(String log);
/**
* Searches the log for records matching the specified parameters. The
@@ -44,7 +58,7 @@
*
* @see #MAX_SEARCH_RESULTS
*/
- SearchResults getMatchingItems(String logFile, String host, String user, String method,
+ SearchResults getMatchingItems(String logName, String host, String user, String method,
String uri, Date startDate, Date endDate,
Integer skipResults, Integer maxResults);
Modified: geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebManager.java?rev=344487&r1=344486&r2=344487&view=diff
==============================================================================
--- geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebManager.java (original)
+++ geronimo/trunk/modules/management/src/java/org/apache/geronimo/management/geronimo/WebManager.java Tue Nov 15 16:13:46 2005
@@ -27,6 +27,11 @@
public final static String PROTOCOL_AJP = "AJP";
/**
+ * Gets the name of the product that this manager manages.
+ */
+ public String getProductName(); //todo: move into NetworkManager
+
+ /**
* Creates a new connector, and returns the ObjectName for it. Note that
* the connector may well require further customization before being fully
* functional (e.g. SSL settings for a secure connector). This may need
Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatLogManagerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatLogManagerImpl.java?rev=344487&r1=344486&r2=344487&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatLogManagerImpl.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatLogManagerImpl.java Tue Nov 15 16:13:46 2005
@@ -27,6 +27,7 @@
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.File;
+import java.io.FilenameFilter;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.MappedByteBuffer;
@@ -36,12 +37,20 @@
import java.text.ParseException;
/**
- * Jetty implementation of the WebAccessLog management interface.
+ * Tomcat implementation of the WebAccessLog management interface.
*
* @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
*/
public class TomcatLogManagerImpl implements TomcatLogManager {
private final static Log log = LogFactory.getLog(TomcatLogManagerImpl.class);
+
+ // Pattern that matches the date in the logfile name
+ private final static Pattern FILENAME_DATE_PATTERN = Pattern.compile("[-_ /.](((19|20)\\d\\d)[-_ /.](0[1-9]|1[012])[-_ /.](0[1-9]|[12][0-9]|3[01]))");
+ private final static int GROUP_FILENAME_FULL_DATE = 1;
+ private final static int GROUP_FILENAME_YEAR = 2;
+ private final static int GROUP_FILENAME_MONTH = 4;
+ private final static int GROUP_FILENAME_DAY = 5;
+
// Pattern that matches a single line (used to calculate line numbers)
private final static Pattern FULL_LINE_PATTERN = Pattern.compile("^.*", Pattern.MULTILINE);
private final static Pattern ACCESS_LOG_PATTERN = Pattern.compile("(\\S*) (\\S*) (\\S*) \\[(.*)\\] \\\"(\\S*) (\\S*).*?\\\" (\\S*) (\\S*).*");
@@ -62,105 +71,185 @@
this.logGbeans = logGbeans;
}
- public String[] getLogFileNames() {
- List files = new ArrayList();
+ /**
+ * Gets the name of all logs used by this system. Typically there
+ * is only one, but specialized cases may use more.
+ *
+ * @return An array of all log names
+ *
+ */
+ public String[] getLogNames() {
+ List logNames = new ArrayList();
for (Iterator it = logGbeans.iterator(); it.hasNext();) {
ValveGBean logGBean = (ValveGBean) it.next();
- AccessLogValve log = (AccessLogValve) logGBean.getInternalObject();
- files.add(log.getPrefix()+"DATE"+log.getSuffix());
+ AccessLogValve logFile = (AccessLogValve) logGBean.getInternalObject();
+ if(logFile != null) {
+ logNames.add( "var/catalina/logs/"+logFile.getPrefix()+LOG_FILE_NAME_FORMAT+logFile.getSuffix());
+ }
}
- return (String[]) files.toArray(new String[files.size()]);
+ return (String[]) logNames.toArray(new String[logNames.size()]);
}
- public SearchResults getMatchingItems(String logFile, String host, String user, String method, String uri,
- Date startDate, Date endDate, Integer skipResults, Integer maxResults) {
- File log = null;
- SimpleDateFormat format = new SimpleDateFormat(LOG_FILE_NAME_FORMAT);
- for (Iterator it = logGbeans.iterator(); it.hasNext();) {
- ValveGBean logGBean = (ValveGBean) it.next();
- AccessLogValve logger = (AccessLogValve) logGBean.getInternalObject();
- if(logFile.equals(logger.getPrefix()+"DATE"+logger.getSuffix())) {
- String path = "var/catalina/logs/"+logger.getPrefix()+format.format(startDate == null ? new Date() : startDate)+logger.getSuffix();
- log = new File(serverInfo.resolvePath(path));
- break;
+ /**
+ * Gets the names of all log files for this log name.
+ *
+ * @param logName The name of the log for which to return the specific file names.
+ *
+ * @return An array of log file names
+ *
+ */
+ public String[] getLogFileNames(String logName) {
+ List names = new ArrayList();
+
+ // Find all the files for this logName
+ File[] logFiles = getLogFiles(logName);
+
+ if (logFiles !=null) {
+ for (int i = 0; i < logFiles.length; i++) {
+ names.add(logFiles[i].getName());
}
}
- if(log == null) {
- throw new IllegalArgumentException("Unknown log file '"+logFile+"'");
- }
+ return (String[]) names.toArray(new String[names.size()]);
+ }
+
+ /**
+ * Gets the name of all log files used by this log. Typically there
+ * is only one, but specialized cases may use more.
+ *
+ * @param logName The name of the log for which to return the specific files.
+ *
+ * @return An array of all log file names
+ *
+ */
+ private File[] getLogFiles(String logName) {
+ File[] logFiles = null;
+
+ try {
+ String fileNamePattern = logName;
+ if (fileNamePattern.indexOf("/") > -1) {
+ fileNamePattern = fileNamePattern.substring(fileNamePattern.lastIndexOf("/") + 1);
+ } else if (fileNamePattern.indexOf("\\") > -1) {
+ fileNamePattern = fileNamePattern.substring(fileNamePattern.lastIndexOf("\\") + 1);
+ }
+
+ String logFile = serverInfo.resolvePath(logName);
- return search(log, host, user, method, uri, startDate, endDate, skipResults, maxResults);
+ File parent = new File(logFile).getParentFile();
+
+ if (parent != null) {
+ logFiles = parent.listFiles(new PatternFilenameFilter(fileNamePattern));
+ }
+ } catch (Exception e) {
+ log.error("Exception attempting to locate Tomcat log files: "+e);
+ logFiles = new File[0];
+ e.printStackTrace();
+ }
+ return logFiles;
}
- private SearchResults search(File file, String host, String user, String method, String uri, Date startDate,
- Date endDate, Integer skipResults, Integer maxResults) {
+ /**
+ * Searches the log for records matching the specified parameters. The
+ * maximum results returned will be the lesser of 1000 and the
+ * provided maxResults argument.
+ *
+ * @see #MAX_SEARCH_RESULTS
+ */
+ public SearchResults getMatchingItems(String logName, String host, String user, String method, String uri,
+ Date startDate, Date endDate, Integer skipResults, Integer maxResults) {
+
// Clean up the arguments so we know what we've really got
if(host != null && host.equals("")) host = null;
if(user != null && user.equals("")) user = null;
if(method != null && method.equals("")) method = null;
if(uri != null && uri.equals("")) uri = null;
- // Do the search
+
+ long start = startDate == null ? 0 : startDate.getTime();
+ long end = endDate == null ? 0 : endDate.getTime();
+
List list = new LinkedList();
boolean capped = false;
- int lineCount = 0;
- try {
- RandomAccessFile raf = new RandomAccessFile(file, "r");
- FileChannel fc = raf.getChannel();
- MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
- CharBuffer cb = Charset.forName("US-ASCII").decode(bb); //todo: does Jetty use a different charset on a foreign PC?
- Matcher lines = FULL_LINE_PATTERN.matcher(cb);
- Matcher target = ACCESS_LOG_PATTERN.matcher("");
- long start = startDate == null ? 0 : startDate.getTime();
- long end = endDate == null ? 0 : endDate.getTime();
- SimpleDateFormat format = (start == 0 && end == 0) ? null : new SimpleDateFormat(ACCESS_LOG_DATE_FORMAT);
- int max = maxResults == null ? MAX_SEARCH_RESULTS : Math.min(maxResults.intValue(), MAX_SEARCH_RESULTS);
- while(lines.find()) {
- ++lineCount;
- if(capped) {
- continue;
- }
- CharSequence line = cb.subSequence(lines.start(), lines.end());
- target.reset(line);
- if(target.find()) {
- if(host != null && !host.equals(target.group(GROUP_HOST))) {
- continue;
- }
- if(user != null && !user.equals(target.group(GROUP_USER))) {
- continue;
- }
- if(method != null && !method.equals(target.group(GROUP_METHOD))) {
- continue;
- }
- if(uri != null && !target.group(GROUP_URI).startsWith(uri)) {
- continue;
- }
- if(format != null) {
- try {
- long entry = format.parse(target.group(GROUP_DATE)).getTime();
- if(start > entry) {
+ int lineCount = 0, fileLineCount = 0;
+
+ // Find all the files for this logName
+ File logFiles[] = getLogFiles(logName);
+
+ if (logFiles !=null) {
+ for (int i = 0; i < logFiles.length; i++) {
+ fileLineCount = 0;
+ try {
+ // Obtain the date for the current log file
+ String fileName = logFiles[i].getName();
+ Matcher fileDate = FILENAME_DATE_PATTERN.matcher(fileName);
+ fileDate.find();
+ SimpleDateFormat simpleFileDate = new SimpleDateFormat(LOG_FILE_NAME_FORMAT);
+ long logFileTime = simpleFileDate.parse(fileDate.group(GROUP_FILENAME_FULL_DATE)).getTime();
+ Date logFileDate = new Date(logFileTime);
+
+ // Check if the dates are null (ignore) or fall within the search range
+ if ( (start==0 && end==0)
+ || (start>0 && start<=logFileTime && end>0 && end>=logFileTime)) {
+
+ // It's in the range, so process the file
+ RandomAccessFile raf = new RandomAccessFile(logFiles[i], "r");
+ FileChannel fc = raf.getChannel();
+ MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
+ CharBuffer cb = Charset.forName("US-ASCII").decode(bb); //todo: does Tomcat use a different charset on a foreign PC?
+ Matcher lines = FULL_LINE_PATTERN.matcher(cb);
+ Matcher target = ACCESS_LOG_PATTERN.matcher("");
+ SimpleDateFormat format = (start == 0 && end == 0) ? null : new SimpleDateFormat(ACCESS_LOG_DATE_FORMAT);
+ int max = maxResults == null ? MAX_SEARCH_RESULTS : Math.min(maxResults.intValue(), MAX_SEARCH_RESULTS);
+
+ while(lines.find()) {
+ ++lineCount;
+ ++fileLineCount;
+ if(capped) {
continue;
}
- if(end > 0 && end < entry) {
- continue;
+ CharSequence line = cb.subSequence(lines.start(), lines.end());
+ target.reset(line);
+ if(target.find()) {
+ if(host != null && !host.equals(target.group(GROUP_HOST))) {
+ continue;
+ }
+ if(user != null && !user.equals(target.group(GROUP_USER))) {
+ continue;
+ }
+ if(method != null && !method.equals(target.group(GROUP_METHOD))) {
+ continue;
+ }
+ if(uri != null && !target.group(GROUP_URI).startsWith(uri)) {
+ continue;
+ }
+ if(format != null) {
+ try {
+ long entry = format.parse(target.group(GROUP_DATE)).getTime();
+ if(start > entry) {
+ continue;
+ }
+ if(end > 0 && end < entry) {
+ continue;
+ }
+ } catch (ParseException e) {
+ // can't read the date, guess this record counts.
+ }
+ }
+ if(skipResults != null && skipResults.intValue() > lineCount) {
+ continue;
+ }
+ if(list.size() > max) {
+ capped = true;
+ continue;
+ }
+ list.add(new LogMessage(fileLineCount,line.toString()));
}
- } catch (ParseException e) {
- // can't read the date, guess this record counts.
}
+ fc.close();
+ raf.close();
}
- if(skipResults != null && skipResults.intValue() > lineCount) {
- continue;
- }
- if(list.size() > max) {
- capped = true;
- continue;
- }
- list.add(new LogMessage(lineCount,line.toString()));
+ } catch (Exception e) {
+ log.error("Unexpected error processing logs", e);
}
}
- fc.close();
- raf.close();
- } catch (Exception e) {
- log.error("Unexpected error processing logs", e);
}
return new SearchResults(lineCount, (LogMessage[]) list.toArray(new LogMessage[list.size()]), capped);
}
@@ -169,7 +258,7 @@
public static final GBeanInfo GBEAN_INFO;
static {
- GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Jetty Log Manager", TomcatLogManagerImpl.class);
+ GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Tomcat Log Manager", TomcatLogManagerImpl.class);
infoFactory.addReference("LogGBeans", ValveGBean.class);
infoFactory.addReference("ServerInfo", ServerInfo.class, "GBean");
infoFactory.addInterface(TomcatLogManager.class);
@@ -181,6 +270,29 @@
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
+
+ /*
+ * Static inner class implementation of java.io.Filename. This will help us
+ * filter for only the files that we are interested in.
+ */
+ static class PatternFilenameFilter implements FilenameFilter {
+ Pattern pattern;
+
+ PatternFilenameFilter(String fileNamePattern) {
+ fileNamePattern = fileNamePattern.replaceAll("yyyy", "\\\\d{4}");
+ fileNamePattern = fileNamePattern.replaceAll("yy", "\\\\d{2}");
+ fileNamePattern = fileNamePattern.replaceAll("mm", "\\\\d{2}");
+ fileNamePattern = fileNamePattern.replaceAll("MM", "\\\\d{2}");
+ fileNamePattern = fileNamePattern.replaceAll("dd", "\\\\d{2}")
+ + ".*";
+ this.pattern = Pattern.compile(fileNamePattern);
+ }
+
+ public boolean accept(File file, String fileName) {
+ return pattern.matcher(fileName).matches();
+ }
+ }
+
/*
public static void main(String[] args) {
String jetty = "127.0.0.1 - - [07/Sep/2005:19:54:41 +0000] \"GET /console/ HTTP/1.1\" 302 0 \"-\" \"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050715 Firefox/1.0.6 SUSE/1.0.6-4.1\" -";
Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatManagerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatManagerImpl.java?rev=344487&r1=344486&r2=344487&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatManagerImpl.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/TomcatManagerImpl.java Tue Nov 15 16:13:46 2005
@@ -50,6 +50,10 @@
this.kernel = kernel;
}
+ public String getProductName() {
+ return "Tomcat";
+ }
+
/**
* Creates a new connector, and returns the ObjectName for it. Note that the connector may well require further
* customization before being fully functional (e.g. SSL settings for a secure connector). This may need to be done