feat(show): 打开日志功能并优化代码
- 在托盘菜单中添加"打开日志"选项 - 实现日志路径获取方法 - 修改文件扫描逻辑,使用 Base64 编码 - 更新项目版本号至 0.1.6.9
This commit is contained in:
parent
14ac73b5dd
commit
5a4a0dae15
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>org.aohe</groupId>
|
<groupId>org.aohe</groupId>
|
||||||
<artifactId>twain-service</artifactId>
|
<artifactId>twain-service</artifactId>
|
||||||
<version>0.1.6.7</version>
|
<version>0.1.6.9</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.aohe.control;
|
package org.aohe.control;
|
||||||
|
|
||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.core.io.FileUtil;
|
|
||||||
import cn.hutool.core.lang.Console;
|
import cn.hutool.core.lang.Console;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -234,13 +233,11 @@ public class Operational {
|
||||||
initSettings(source);
|
initSettings(source);
|
||||||
source.setName(name);
|
source.setName(name);
|
||||||
List<File> fileList = source.scan();
|
List<File> fileList = source.scan();
|
||||||
List<String> filePath = new ArrayList<>();
|
List<String> base64Files = new ArrayList<>();
|
||||||
for (File file : fileList){
|
for (File file : fileList){
|
||||||
String absolutePath = FileUtil.getAbsolutePath(file);
|
base64Files.add(Base64.encode(file));
|
||||||
filePath.add(absolutePath);
|
|
||||||
}
|
}
|
||||||
|
return R.ok(base64Files);
|
||||||
return R.ok(filePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initSettings(Source source) {
|
private static void initSettings(Source source) {
|
||||||
|
|
|
@ -2,12 +2,14 @@ package org.aohe.show;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aohe.constant.SocketEnum;
|
import org.aohe.constant.SocketEnum;
|
||||||
|
import org.aohe.utils.LogUtil;
|
||||||
import org.aohe.web.SocketUtils;
|
import org.aohe.web.SocketUtils;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
@ -55,6 +57,7 @@ public class TrayFrameUtf8 {
|
||||||
|
|
||||||
JMenuItem startServiceItem = new JMenuItem("启动服务");
|
JMenuItem startServiceItem = new JMenuItem("启动服务");
|
||||||
JMenuItem stopServiceItem = new JMenuItem("停止服务");
|
JMenuItem stopServiceItem = new JMenuItem("停止服务");
|
||||||
|
JMenuItem logItem = new JMenuItem("打开日志");
|
||||||
startServiceItem.setEnabled(false);
|
startServiceItem.setEnabled(false);
|
||||||
stopServiceItem.setEnabled(true);
|
stopServiceItem.setEnabled(true);
|
||||||
startServiceItem.addActionListener(e ->{
|
startServiceItem.addActionListener(e ->{
|
||||||
|
@ -75,10 +78,21 @@ public class TrayFrameUtf8 {
|
||||||
log.info("服务已停止");
|
log.info("服务已停止");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logItem.addActionListener(e -> {
|
||||||
|
try {
|
||||||
|
String logPath = LogUtil.getLogPath();
|
||||||
|
Desktop.getDesktop().open(new File(logPath));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.info("打开文件出现错误...");
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
jPopupMenu.add(startServiceItem);
|
jPopupMenu.add(startServiceItem);
|
||||||
jPopupMenu.add(stopServiceItem);
|
jPopupMenu.add(stopServiceItem);
|
||||||
|
jPopupMenu.add(logItem);
|
||||||
|
|
||||||
jPopupMenu.add(showMainFrame);
|
jPopupMenu.add(showMainFrame);
|
||||||
jPopupMenu.add(exit);
|
jPopupMenu.add(exit);
|
||||||
Image image = IconUtil.getIcon();
|
Image image = IconUtil.getIcon();
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.aohe.utils;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.LoggerContext;
|
||||||
|
import ch.qos.logback.core.FileAppender;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class LogUtil {
|
||||||
|
public static String getLogPath() throws IOException {
|
||||||
|
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||||
|
ch.qos.logback.classic.Logger logger = context.getLogger("ROOT");
|
||||||
|
FileAppender fileAppender = (FileAppender) logger.getAppender("file");//"file"是 logback 配置中,输出日志文件的 appender 的 name 属性
|
||||||
|
File file = new File(fileAppender.getFile());
|
||||||
|
return file.getCanonicalPath();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue