modify log page
This commit is contained in:
parent
d604d4b3f8
commit
ea85d53d04
6 changed files with 74 additions and 84 deletions
|
@ -15,18 +15,33 @@
|
|||
*/
|
||||
package org.codelibs.fess.app.web.admin.log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.exception.FessSystemException;
|
||||
import org.codelibs.fess.helper.SystemHelper;
|
||||
import org.lastaflute.di.exception.IORuntimeException;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.callback.ActionRuntime;
|
||||
import org.lastaflute.web.response.ActionResponse;
|
||||
import org.lastaflute.web.response.HtmlResponse;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
/**
|
||||
* @author codelibs
|
||||
* @author Keiichi Watanabe
|
||||
|
@ -43,46 +58,57 @@ public class AdminLogAction extends FessAdminAction {
|
|||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse index(final LogForm form) {
|
||||
public HtmlResponse index() {
|
||||
return toIndexPage();
|
||||
}
|
||||
|
||||
@Execute
|
||||
public ActionResponse download(final String id) {
|
||||
String filename = new String(Base64.getDecoder().decode(id), Charsets.UTF_8).replace("..", "").replaceAll("\\s", "");
|
||||
final String logFilePath = systemHelper.getLogFilePath();
|
||||
if (StringUtil.isNotBlank(logFilePath)) {
|
||||
Path path = Paths.get(logFilePath, filename);
|
||||
return asStream(filename).contentType("text/plain; charset=UTF-8").stream(out -> {
|
||||
try (InputStream in = Files.newInputStream(path)) {
|
||||
out.write(in);
|
||||
}
|
||||
});
|
||||
}
|
||||
throwValidationError(messages -> messages.addErrorsCouldNotFindLogFile(GLOBAL, filename), () -> {
|
||||
return toIndexPage();
|
||||
});
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getLogFileItems() {
|
||||
final List<Map<String, Object>> logFileItems = new ArrayList<Map<String, Object>>();
|
||||
final String logFilePath = systemHelper.getLogFilePath();
|
||||
if (StringUtil.isNotBlank(logFilePath)) {
|
||||
Path logDirPath = Paths.get(logFilePath);
|
||||
try (Stream<Path> stream = Files.list(logDirPath)) {
|
||||
stream.filter(entry -> entry.getFileName().toString().endsWith(".log")).forEach(filePath -> {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String name = filePath.getFileName().toString();
|
||||
map.put("id", Base64.getEncoder().encodeToString(name.getBytes(Charsets.UTF_8)));
|
||||
map.put("name", name);
|
||||
try {
|
||||
map.put("lastModified", new Date(Files.getLastModifiedTime(filePath).toMillis()));
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
logFileItems.add(map);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new FessSystemException("Failed to access log files.", e);
|
||||
}
|
||||
}
|
||||
return logFileItems;
|
||||
}
|
||||
|
||||
private HtmlResponse toIndexPage() {
|
||||
return asHtml(path_AdminLog_IndexJsp).renderWith(data -> {
|
||||
data.register("logFileItems", getLogFileItems());
|
||||
});
|
||||
}
|
||||
|
||||
//@Execute(validator = true, input = "index", urlPattern = "download/{logFileName}")
|
||||
public HtmlResponse download(final LogForm form) {
|
||||
// TODO
|
||||
return redirect(getClass());
|
||||
/*
|
||||
final String logFilePath = ComponentUtil.getSystemHelper().getLogFilePath();
|
||||
if (StringUtil.isNotBlank(logFilePath)) {
|
||||
final File file = new File(logFilePath);
|
||||
final File parentDir = file.getParentFile();
|
||||
String fileName;
|
||||
try {
|
||||
fileName = new String(Base64.decodeBase64(logForm.logFileName.getBytes(Constants.UTF_8)), Constants.UTF_8);
|
||||
} catch (final UnsupportedEncodingException e1) {
|
||||
fileName =
|
||||
new String(Base64.decodeBase64(logForm.logFileName.getBytes(Charset.defaultCharset())), Charset.defaultCharset());
|
||||
}
|
||||
final File logFile = new File(parentDir, fileName);
|
||||
if (logFile.isFile()) {
|
||||
try {
|
||||
LaResponseUtil.download(fileName, new FileInputStream(logFile));
|
||||
return null;
|
||||
} catch (final FileNotFoundException e) {
|
||||
logger.warn("Could not find " + logFile.getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new SSCActionMessagesException("errors.could_not_find_log_file", new Object[] { logForm.logFileName });
|
||||
*/
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getLogFileItems() {
|
||||
// TODO
|
||||
final List<Map<String, Object>> logFileItems = new ArrayList<Map<String, Object>>();
|
||||
return logFileItems;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright 2012-2015 CodeLibs Project and the Others.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.codelibs.fess.app.web.admin.log;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author codelibs
|
||||
* @author Keiichi Watanabe
|
||||
*/
|
||||
public class LogForm implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public String logFileName;
|
||||
}
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package org.codelibs.fess.helper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
@ -60,8 +61,6 @@ public class SystemHelper implements Serializable {
|
|||
"-XX:CompressedClassSpaceSize=32m", "-XX:-UseGCOverheadLimit", "-XX:+UseConcMarkSweepGC",
|
||||
"-XX:CMSInitiatingOccupancyFraction=75", "-XX:+UseParNewGC", "-XX:+UseTLAB", "-XX:+DisableExplicitGC" };
|
||||
|
||||
private String logFilePath = System.getProperty("fess.log.path", "target/logs");
|
||||
|
||||
private String javaCommandPath = "java";
|
||||
|
||||
private String filterPathEncoding = Constants.UTF_8;
|
||||
|
@ -133,11 +132,14 @@ public class SystemHelper implements Serializable {
|
|||
}
|
||||
|
||||
public String getLogFilePath() {
|
||||
return logFilePath;
|
||||
}
|
||||
|
||||
public void setLogFilePath(final String logFilePath) {
|
||||
this.logFilePath = logFilePath;
|
||||
final String value = System.getProperty("fess.log.path");
|
||||
if (value != null) {
|
||||
return value;
|
||||
} else {
|
||||
final String userDir = System.getProperty("user.dir");
|
||||
final File targetDir = new File(userDir, "target");
|
||||
return new File(targetDir, "logs").getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
public String encodeUrlFilter(final String path) {
|
||||
|
|
|
@ -269,11 +269,7 @@ public class CrawlJob {
|
|||
}
|
||||
|
||||
crawlerCmdList.add("-Dfess.crawler.process=true");
|
||||
if (logFilePath == null) {
|
||||
final String value = System.getProperty("fess.log.path");
|
||||
logFilePath = value != null ? value : new File(targetDir, "logs").getAbsolutePath();
|
||||
}
|
||||
crawlerCmdList.add("-Dfess.log.path=" + logFilePath);
|
||||
crawlerCmdList.add("-Dfess.log.path=" + (logFilePath != null ? logFilePath : systemHelper.getLogFilePath()));
|
||||
addSystemProperty(crawlerCmdList, "lasta.env", null, null);
|
||||
addSystemProperty(crawlerCmdList, "fess.log.name", "fess-crawler", "-crawler");
|
||||
addSystemProperty(crawlerCmdList, "fess.log.level", null, null);
|
||||
|
|
|
@ -33,11 +33,6 @@
|
|||
"hi", "hu", "hy", "id", "it", "ja", "lv", "ko", "nl", "no", "pt",
|
||||
"ro", "ru", "sv", "th", "tr", "zh_CN", "zh_TW", "zh" }</property>
|
||||
-->
|
||||
<property name="logFilePath">
|
||||
java.lang.System.getProperty("fess.log.file") == null ?
|
||||
java.lang.System.getProperty("java.io.tmpdir") + "/fess_crawler.out" :
|
||||
java.lang.System.getProperty("fess.log.file").replaceAll(".out", "_crawler.out")
|
||||
</property>
|
||||
<property name="crawlerJavaOptions">
|
||||
[
|
||||
"-Djava.awt.headless=true",
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
<c:forEach var="logFile" varStatus="s" items="${logFileItems}">
|
||||
<tr class="${s.index % 2 == 0 ? 'row1' : 'row2'}">
|
||||
<td>
|
||||
<la:link href="download/${f:u(logFile.logFileName)}">${f:h(logFile.name)}</la:link>
|
||||
<la:link href="download/${f:u(logFile.id)}" target="_blank">${f:h(logFile.name)}</la:link>
|
||||
</td>
|
||||
<td style="overflow-x: auto;">
|
||||
<fmt:formatDate value="${logFile.lastModified}" type="BOTH" dateStyle="MEDIUM" />
|
||||
|
|
Loading…
Add table
Reference in a new issue