<%-- - $RCSfile$ - $Revision$ - $Date$ - - Copyright (C) 2004-2008 Jive Software. All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> <%@ page import="java.io.*, java.text.SimpleDateFormat, java.util.Date, java.text.ParseException, org.jivesoftware.util.ParamUtils, org.jivesoftware.util.Log, org.jivesoftware.util.StringUtils" errorPage="error.jsp" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%! static final SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd kk:mm:ss"); private static String parseDate(String input) { if (input == null || "".equals(input)) { return input; } if (input.length() < 19) { return input; } String d = input.substring(0,19); // try to parse it try { StringBuffer buf = new StringBuffer(input.length()); synchronized (formatter) { Date date = formatter.parse(d); buf.append(""); } buf.append(d).append(""); buf.append(input.substring(19,input.length())); return buf.toString(); } catch (ParseException pe) { return input; } } private static String hilite(String input) { if (input == null || "".equals(input)) { return input; } if (input.indexOf("org.jivesoftware.") > -1) { StringBuffer buf = new StringBuffer(); buf.append("").append(input).append(""); return buf.toString(); } else if (input.trim().startsWith("---") && input.trim().endsWith("---")) { StringBuffer buf = new StringBuffer(); buf.append("").append(input).append(""); return buf.toString(); } return input; } %> <% // Get parameters String log = ParamUtils.getParameter(request,"log"); String numLinesParam = ParamUtils.getParameter(request,"lines"); int numLines = ParamUtils.getIntParameter(request,"lines",50); String mode = ParamUtils.getParameter(request,"mode"); // Only allow requests for valid log file names. if (!("debug".equals(log) || "warn".equals(log) || "info".equals(log) || "error".equals(log))) { log = null; } // Set defaults if (log == null) { log = "error"; } if (mode == null) { mode = "asc"; } if (numLinesParam == null) { numLinesParam = "50"; } // Other vars File logDir = new File(Log.getLogDirectory()); String filename = log + ".log"; File logFile = new File(logDir, filename); String lines[] = new String[0]; int start = 0; try { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(logFile), "UTF-8")); String line; int totalNumLines = 0; while ((line=in.readLine()) != null) { totalNumLines++; } in.close(); // adjust the 'numLines' var to match totalNumLines if 'all' was passed in: if ("All".equals(numLinesParam)) { numLines = totalNumLines; } lines = new String[numLines]; in = new BufferedReader(new InputStreamReader(new FileInputStream(logFile), "UTF-8")); // skip lines start = totalNumLines - numLines; if (start < 0) { start = 0; } for (int i=0; i <%= log %>
 
<% if ("asc".equals(mode)) { %> <% for (int j=start+1; j<=numLines; j++) { %> <%= j %>
<% } %> <% } else { %> <% for(int j=numLines; j>=start+1; j--) { %> <%= j %>
<% } %> <% } %>
<% for (String line1 : lines) { if (line1 != null) { %> <%= line1 %>
<% } } %>