Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 187c264

Browse files
committed
refactor: optimize log info
1 parent 8b11080 commit 187c264

File tree

10 files changed

+91
-24
lines changed

10 files changed

+91
-24
lines changed

src/main/java/org/code4everything/wetool/WeApplication.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ private static Pane getRootPane() {
114114
}
115115

116116
public static void main(String[] args) {
117+
log.info("starting wetool on os: {}", SystemUtil.getOsInfo().getName());
118+
log.info("default charset: {}", Charset.defaultCharset().name());
117119
BeanFactory.register(new WeStatus().setState(WeStatus.State.STARTING));
118120
addShutdownHook();
119121
boolean debug = BootConfig.isDebug();
@@ -127,17 +129,14 @@ public static void main(String[] args) {
127129
}
128130
}
129131

130-
log.info("starting wetool on os: {}", SystemUtil.getOsInfo().getName());
131-
log.info("default charset: {}", Charset.defaultCharset().name());
132-
133132
parseConfig();
134133
if (debug) {
135134
// 因配置文件可能会修改debug mode,所以这里需要确保解析配置文件后debug模式仍然为true
136135
WeUtils.getConfig().setDebug(true);
137136
BootConfig.setDebug(true);
138137
}
139138
if (BootConfig.isDebug()) {
140-
log.info("debug mode enabled");
139+
log.info("enable debug mode");
141140
}
142141

143142
checkAlreadyRunning();
@@ -146,7 +145,9 @@ public static void main(String[] args) {
146145
}
147146

148147
private static void addShutdownHook() {
148+
log.info("register shutdown hook");
149149
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
150+
log.info("shutting down");
150151
BeanFactory.get(WeStatus.class).setState(WeStatus.State.TERMINATING);
151152
EventCenter.publishEvent(EventCenter.EVENT_WETOOL_EXIT, DateUtil.date());
152153
log.info("close druid data source connections");
@@ -160,7 +161,7 @@ private static void addShutdownHook() {
160161
shutdown = WeUtils.getThreadPoolExecutor().awaitTermination(1000, TimeUnit.MILLISECONDS);
161162
}
162163
if (!shutdown) {
163-
log.info("wait for thread pool shutdown expired, force exit thread pool");
164+
log.info("thread pool shutdown expired, force exit");
164165
WeUtils.getThreadPoolExecutor().shutdownNow();
165166
}
166167
} catch (Exception e) {
@@ -189,8 +190,10 @@ private static void checkAlreadyRunning() {
189190
continue;
190191
}
191192
if (StrUtil.containsIgnoreCase(process, "wetool")) {
193+
log.info("check process[{}] is running", process);
192194
try {
193-
WeStatus.State state = JSON.parseObject(HttpUtil.get("http://127.0.0.1:8189/wetool/status")).getObject("state", WeStatus.State.class);
195+
WeStatus.State state = JSON.parseObject(HttpUtil.get("http://127.0.0.1:8189/wetool/status"), WeStatus.class).getState();
196+
log.info("process[{}] status: {}", process, state.name().toLowerCase());
194197
if (state != WeStatus.State.TERMINATING) {
195198
log.info("wetool is already running, show wetool now");
196199
HttpUtil.get("http://127.0.0.1:8189/wetool/show");
@@ -235,9 +238,10 @@ public static void initApp() {
235238
private static void initKeyboardMouseListener() {
236239
FxUtils.listenKeyEvent();
237240
if (BooleanUtil.isTrue(WeUtils.getConfig().getDisableKeyboardMouseListener())) {
238-
log.info("jnative keyboard mouse listener disabled");
241+
log.info("disable jnative keyboard mouse listener");
239242
if (!SystemUtil.getOsInfo().isMac()) {
240243
// 已知Mac平台下不能正常工作
244+
log.info("register mouse location listener");
241245
EventCenter.on100MsTimer(new MouseLocationListenerEventHandler());
242246
}
243247
return;
@@ -248,6 +252,7 @@ private static void initKeyboardMouseListener() {
248252
logger.setLevel(Level.OFF);
249253
logger.setUseParentHandlers(false);
250254

255+
log.info("register jnative keyboard mouse listener");
251256
try {
252257
GlobalScreen.registerNativeHook();
253258
GlobalScreen.addNativeKeyListener(new WeKeyboardListener());
@@ -354,12 +359,14 @@ private static void setRootPane(Pane rootPane) {
354359
}
355360

356361
public static void recoverRootPane() {
362+
log.info("recover scene root pane");
357363
FxUtils.getStage().setTitle(FinalUtils.getAppTitle());
358364
getRootScene().setRoot(getRootPane());
359365
FxUtils.getStage().setScene(getRootScene());
360366
}
361367

362368
private void listenKeyboard() {
369+
log.info("add javafx keyboard listener");
363370
FxUtils.getStage().getScene().addEventFilter(EventType.ROOT, event -> {
364371
if (event instanceof KeyEvent) {
365372
String eventType = event.getEventType().toString();
@@ -384,6 +391,7 @@ private void listenKeyboard() {
384391

385392
@Override
386393
public void start(Stage stage) {
394+
log.info("starting javafx stage");
387395
BeanFactory.register(stage);
388396

389397
// 注册并发布秒钟定时器事件
@@ -393,6 +401,7 @@ public void start(Stage stage) {
393401
EXECUTOR.scheduleWithFixedDelay(publisher::publishEvent, 0, 1, TimeUnit.SECONDS);
394402

395403
// 加载主界面
404+
log.info("loading wetool main fxml");
396405
Pane root = FxUtils.loadFxml(WeApplication.class, ViewConsts.MAIN, false);
397406
if (Objects.isNull(root)) {
398407
FxDialogs.showError(TipConsts.INIT_ERROR);
@@ -461,6 +470,7 @@ private void setQuickStartMenu(Menu menu, Set<WeStart> starts) {
461470
FxUtils.openFile(start.getLocation());
462471
});
463472
menu.add(item);
473+
log.info("load quick start tray menu, name: {}, file: {}", start.getAlias(), start.getLocation());
464474
} else {
465475
// 添加父级菜单
466476
Menu subMenu = new Menu(start.getAlias());
@@ -474,6 +484,7 @@ private void setQuickStartMenu(Menu menu, Set<WeStart> starts) {
474484
* 开启系统托盘图标
475485
*/
476486
private void enableTray(Stage stage) {
487+
log.info("enable tray icon");
477488
try {
478489
FXTrayIcon icon = new FXTrayIcon(stage, WeApplication.class.getResource(ViewConsts.ICON));
479490
icon.setApplicationTitle(FinalUtils.getAppTitle());
@@ -498,6 +509,7 @@ private void enableTray(Stage stage) {
498509
}
499510

500511
private PopupMenu getPopupMenu() {
512+
log.info("add tray popup menu");
501513
// 添加托盘邮件菜单
502514
PopupMenu popupMenu = new PopupMenu();
503515
// 快捷打开

src/main/java/org/code4everything/wetool/controller/MainController.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import java.util.Set;
8686
import java.util.concurrent.ConcurrentHashMap;
8787
import java.util.regex.Pattern;
88+
import java.util.stream.Collectors;
8889

8990
/**
9091
* @author pantao
@@ -163,6 +164,7 @@ public static void registerAction(String name, EventHandler<ActionEvent> eventHa
163164
if (name.endsWith(StringConsts.Sign.STAR)) {
164165
return;
165166
}
167+
log.info("register search action: {}", name);
166168
String pinyin = PinyinUtil.getPinyin(name);
167169
ACTION_NAME_PINYIN_MAP.put(name, StrUtil.cleanBlank(pinyin));
168170
}
@@ -171,6 +173,7 @@ public static void unregisterAction(String name) {
171173
name = StrUtil.trim(name);
172174
ACTION_MAP.remove(name);
173175
String pinyin = PinyinUtil.getPinyin(name);
176+
log.info("remove search action: {}", name);
174177
ACTION_NAME_PINYIN_MAP.remove(pinyin);
175178
}
176179

@@ -211,6 +214,7 @@ public void handleEvent0(String s, Date date) {
211214
});
212215

213216
// 监听鼠标位置
217+
log.info("add mouse corner trigger");
214218
EventCenter.onMouseMotion(new MouseMotionEventHandler());
215219
multiDesktopOnWindows();
216220

@@ -334,6 +338,7 @@ private void addWebTool() {
334338
WebView browser = getWebView(k, v);
335339
FinalUtils.openTab(browser, "网页工具-" + k);
336340
};
341+
log.info("add web tool: {}", k);
337342
menu.getItems().add(FxUtils.createBarMenuItem(k, handler));
338343
registerAction("网页工具-webtool/" + k, handler);
339344
});
@@ -386,6 +391,7 @@ private void runHutoolCmd(ActionEvent actionEvent) {
386391
private void closeSelectedTab() {
387392
Tab tab = tabPane.getSelectionModel().getSelectedItem();
388393
if (Objects.nonNull(tab)) {
394+
log.info("close tab: {}", tab.getText());
389395
tabPane.getTabs().remove(tab);
390396
}
391397
}
@@ -494,6 +500,7 @@ private void closeTab(int idx) {
494500
return;
495501
}
496502
idx = Math.min(idx, maxIdx);
503+
log.info("close tab at idx: {}", idx);
497504
tabPane.getTabs().remove(idx);
498505
}
499506

@@ -502,6 +509,7 @@ private void multiDesktopOnWindows() {
502509
return;
503510
}
504511

512+
log.info("register windows hot corner trigger");
505513
EventCenter.onSysCornerTrigger(new BaseMouseCornerEventHandler() {
506514
@Override
507515
public void handleEvent0(String s, Date date, MouseCornerEventMessage message) {
@@ -537,6 +545,7 @@ private void setQuickStartMenu(Menu menu, Set<WeStart> starts) {
537545
FxUtils.openFile(start.getLocation());
538546
});
539547
menu.getItems().add(item);
548+
log.info("load quick start bar menu, name: {}, file: {}", start.getAlias(), start.getLocation());
540549
} else {
541550
// 添加父级菜单
542551
Menu subMenu = new Menu(start.getAlias());
@@ -588,6 +597,7 @@ private void openTab(Pair<String, String> tabPair) {
588597

589598
public void openFile() {
590599
FxUtils.chooseFile(file -> {
600+
log.info("choose file: {}", file.getAbsolutePath());
591601
BaseViewController controller = FxUtils.getSelectedTabController();
592602
if (ObjectUtil.isNotNull(controller)) {
593603
controller.openFile(file);
@@ -598,6 +608,7 @@ public void openFile() {
598608
public void saveFile() {
599609
FxUtils.saveFile(file -> {
600610
BaseViewController controller = FxUtils.getSelectedTabController();
611+
log.info("save to file: {}", file.getAbsolutePath());
601612
if (ObjectUtil.isNotNull(controller)) {
602613
controller.saveFile(file);
603614
}
@@ -607,6 +618,8 @@ public void saveFile() {
607618
public void openMultiFile() {
608619
FxUtils.chooseFiles(files -> {
609620
BaseViewController controller = FxUtils.getSelectedTabController();
621+
List<String> list = files.stream().map(File::getAbsolutePath).collect(Collectors.toList());
622+
log.info("choose multi files: {}", list);
610623
if (ObjectUtil.isNotNull(controller)) {
611624
controller.openMultiFiles(files);
612625
}
@@ -616,6 +629,7 @@ public void openMultiFile() {
616629
public void openFolder() {
617630
FxUtils.chooseFolder(folder -> {
618631
BaseViewController controller = FxUtils.getSelectedTabController();
632+
log.info("choose folder: {}", folder.getAbsolutePath());
619633
if (ObjectUtil.isNotNull(controller)) {
620634
controller.openFolder(folder);
621635
}
@@ -645,6 +659,7 @@ public void about() {
645659
}
646660

647661
public void closeAllTab() {
662+
log.info("close all tab");
648663
tabPane.getTabs().clear();
649664
}
650665

@@ -653,6 +668,7 @@ public void openAllTab() {
653668
}
654669

655670
public void openLog() {
671+
log.info("open log file");
656672
FxUtils.openFile(FileConsts.LOG);
657673
}
658674

@@ -661,27 +677,33 @@ public void restart() {
661677
}
662678

663679
public void openConfig() {
680+
log.info("open config file");
664681
FinalUtils.openConfig();
665682
}
666683

667684
public void pluginPane() {
685+
log.info("open plugin page");
668686
Pane pane = FxUtils.loadFxml("/views/PluginManagerView.fxml", false);
669687
FxDialogs.showDialog("插件面板", pane, null);
670688
}
671689

672690
public void openPluginFolder() {
691+
log.info("open plugin folder");
673692
FinalUtils.openPluginFolder();
674693
}
675694

676695
public void openLogFolder() {
696+
log.info("open log folder");
677697
FxUtils.openFile(FileConsts.LOG_FOLDER);
678698
}
679699

680700
public void openWorkFolder() {
701+
log.info("open current work folder");
681702
FxUtils.openFile(FileUtils.currentWorkDir());
682703
}
683704

684705
public void seeJavaInfo() {
706+
log.info("show java info");
685707
TextArea area = new TextArea(getAllJavaInfos());
686708
VBox.setVgrow(area, Priority.ALWAYS);
687709
VBox box = new VBox(area);
@@ -691,6 +713,7 @@ public void seeJavaInfo() {
691713
}
692714

693715
public void clearAllFxmlCache() {
716+
log.info("close all fxml cache");
694717
EventCenter.publishEvent(EventCenter.EVENT_CLEAR_FXML_CACHE, DateUtil.date());
695718
tabPane.getTabs().clear();
696719
WEB_TOOL_BROWSER_MAP.clear();
@@ -761,6 +784,7 @@ public void toolBoxKeyReleased(KeyEvent keyEvent) {
761784
if (Objects.isNull(eventHandler)) {
762785
FxDialogs.showError("未找到对应的工具!");
763786
} else {
787+
log.info("execute action: {}", keyword);
764788
eventHandler.handle(new ActionEvent(keyword, null));
765789
}
766790

@@ -803,6 +827,7 @@ private EventHandler<ActionEvent> getActionEventEventHandler(String keyword, Str
803827

804828
key = key.substring(0, key.length() - 1);
805829
if (trimmedKeyword.startsWith(key) && Objects.nonNull(entry.getValue())) {
830+
log.info("get pattern[{}] matched action: {}", key, entry.getKey());
806831
return entry.getValue();
807832
}
808833
}

src/main/java/org/code4everything/wetool/controller/NetworkToolController.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
@Slf4j
3434
public class NetworkToolController implements BaseViewController {
3535

36+
private static final List<Integer> POST_LIST = new ArrayList<>();
37+
38+
static {
39+
for (int i = 1; i <= 65535; i++) {
40+
POST_LIST.add(i);
41+
}
42+
}
43+
3644
@FXML
3745
public TextField privateIpv4;
3846

@@ -48,14 +56,6 @@ public class NetworkToolController implements BaseViewController {
4856
@FXML
4957
public TextField domainIp;
5058

51-
private static final List<Integer> POST_LIST = new ArrayList<>();
52-
53-
static {
54-
for (int i = 1; i <= 65535; i++) {
55-
POST_LIST.add(i);
56-
}
57-
}
58-
5959
@FXML
6060
public TextField ipOfPortScan;
6161

@@ -101,6 +101,7 @@ public void scanPort() {
101101
List<Future<Integer>> futureList = ListUtil.split(POST_LIST, 10000).stream().map(ports -> WeUtils.executeAsync(() -> {
102102
ports.forEach(port -> {
103103
try {
104+
log.info("scanning port: {}", port);
104105
Socket socket = new Socket();
105106
SocketAddress socketAddress = new InetSocketAddress(ip, port);
106107
socket.connect(socketAddress, 200);

src/main/java/org/code4everything/wetool/controller/PluginManagerController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ public void installPlugin() {
111111
return;
112112
}
113113
File pluginFolder = WeUtils.getPluginFolder();
114+
log.info("downloading plugin from url: {}", url);
114115
File plugin = HttpUtil.downloadFileFromUrl(url, pluginFolder);
115116
if (isZip(plugin.getName())) {
117+
log.info("unzip plugin file to plugin folder");
116118
ZipUtil.unzip(plugin, pluginFolder);
117119
try (ZipFile zipFile = new ZipFile(plugin)) {
118120
ZipUtil.listFileNames(zipFile, "").forEach(e -> loadPlugin(FileUtil.file(pluginFolder, e)));

src/main/java/org/code4everything/wetool/controller/converter/CharsetConverterController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ public void recognizeCharset() {
133133
FxUtils.chooseFile(file -> {
134134
// 设置文件路径
135135
filePath.setText(file.getAbsolutePath());
136-
fileCharset.setText(EncodingDetect.getJavaEncode(file.getAbsolutePath()));
136+
String charset = EncodingDetect.getJavaEncode(file.getAbsolutePath());
137+
log.info("recognize file[{}] charset: {}", file.getAbsolutePath(), charset);
138+
fileCharset.setText(charset);
137139
});
138140
}
139141

@@ -157,6 +159,7 @@ public void convert2File() {
157159
if (file.exists()) {
158160
String content = FileUtil.readString(file, fileCharset.getText());
159161
Charset charset = Charset.forName(targetCharset.getValue());
162+
log.info("convert file[{}] to charset: {}", file.getAbsolutePath(), charset.name());
160163
FileUtil.writeString(content, file, charset);
161164
fileCharset.setText(charset.toString());
162165
}
@@ -189,6 +192,7 @@ private void batchConvert(List<File> files, final Charset charset) {
189192
if (file.isFile()) {
190193
String srcCharset = EncodingDetect.getJavaEncode(file.getAbsolutePath());
191194
FileUtil.writeString(FileUtil.readString(file, srcCharset), file, charset);
195+
log.info("convert file[{}] to charset: {}", file.getAbsolutePath(), charset.name());
192196
}
193197
if (file.isDirectory()) {
194198
File[] fileArr = file.listFiles();

0 commit comments

Comments
 (0)