if (WindowState.MINIMIZED.equals(renderRequest.getWindowState())) {
return;
}
String action = renderRequest.getParameter("action");
SystemLog log = PortletManager.getCurrentSystemLog(renderRequest);
String[] logFiles = log.getLogFileNames();
LogFile[] files = new LogFile[logFiles.length];
for (int i = 0; i < files.length; i++) {
files[i] = new LogFile(logFiles[i]);
}
Criteria criteria = (Criteria) renderRequest.getPortletSession(true).getAttribute(CRITERIA_KEY, PortletSession.PORTLET_SCOPE);
if(criteria != null) {
// Check if criteria.logFile is in the logFileNames of current logging configuration
boolean found = false;
for(String logFile: logFiles) {
if(criteria.logFile.equals(new File(logFile))) {
found = true;
break;
}
}
if(!found) {
// This arises when log4j properties file is changed dynamically using LogManagerPortlet
// and the earlier log file is no longer in the current logging configuration.
// Change the log file to any one in the current logging configuration so that LogViewer
// won't run into errors.
criteria.logFile = logFiles[0];
}
}
if (criteria == null || (action != null && !"refresh".equals(action))) {
if(criteria == null)
criteria = new Criteria();
String startPos = renderRequest.getParameter("startPos");
String endPos = renderRequest.getParameter("endPos");
String maxRows = renderRequest.getParameter("maxRows");
String logLevel = renderRequest.getParameter("logLevel");
String searchString = renderRequest.getParameter("searchString");
String stackTraces = renderRequest.getParameter("stackTraces");
String logFile = renderRequest.getParameter("logFile");
if(logFile == null || logFile.equals("")) {
logFile = logFiles[0];
}
criteria.level = logLevel == null || logLevel.equals("") ? criteria.level : logLevel;
try{
criteria.max = maxRows == null || maxRows.equals("") ? criteria.max : Integer.parseInt(maxRows);
}catch(NumberFormatException e){
//ignore
}
try{
criteria.start = startPos == null || startPos.equals("") ? null : new Integer(startPos);
}catch(NumberFormatException e){
//ignore
}
try{
criteria.stop = endPos == null || endPos.equals("") ? null : new Integer(endPos);
}catch(NumberFormatException e){
//ignore
}
criteria.logFile = logFile;
criteria.stackTraces = stackTraces != null && !stackTraces.equals("");
criteria.text = searchString == null || searchString.equals("") ? null : searchString;
renderRequest.getPortletSession(true).setAttribute(CRITERIA_KEY, criteria, PortletSession.PORTLET_SCOPE);
}
SystemLog.SearchResults results = log.getMatchingItems(criteria.logFile, criteria.start, criteria.stop,
criteria.level, criteria.text, criteria.max, criteria.stackTraces);
renderRequest.setAttribute("searchResults", results.getResults());
renderRequest.setAttribute("lineCount", new Integer(results.getLineCount()));
renderRequest.setAttribute("startPos", criteria.start);
renderRequest.setAttribute("endPos", criteria.stop);