Skip to content

Commit 5cceb90

Browse files
committed
🔊 修正日志格式
1 parent c41df4f commit 5cceb90

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

src/main/java/com/pcdd/sonovel/action/AggregatedSearchAction.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.pcdd.sonovel.action;
22

3+
import cn.hutool.core.collection.CollUtil;
34
import cn.hutool.core.lang.Console;
45
import com.pcdd.sonovel.core.Source;
56
import com.pcdd.sonovel.handle.SearchResultsHandler;
@@ -36,6 +37,11 @@ public void execute() {
3637

3738
List<SearchResult> results = getSearchResults(kw);
3839

40+
if (CollUtil.isEmpty(results)) {
41+
Console.log(render("聚合搜索结果为空!", "yellow"));
42+
return;
43+
}
44+
3945
SearchParser.printAggregateSearchResult(results);
4046

4147
new DownloadAction(null).execute(results);
@@ -51,7 +57,7 @@ public static List<SearchResult> getSearchResults(String kw) {
5157
threadPool.execute(() -> {
5258
List<SearchResult> res = new SearchParser(source.config).parse(kw);
5359
Rule rule = source.rule;
54-
Console.log("==> 书源 {} ({}) 搜索到 {} 条记录", rule.getId(), rule.getName(), res.size());
60+
Console.log("<== 书源 {} ({})\t搜索到 {} 条记录", rule.getId(), rule.getName(), res.size());
5561
results.add(res);
5662
latch.countDown();
5763
});

src/main/java/com/pcdd/sonovel/core/Source.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public Source(int id, AppConfig config) {
4040
// 根据 sourceId 获取对应书源规则
4141
jsonStr = ResourceUtil.readUtf8Str("rule/rule-" + id + ".json");
4242
} catch (Exception e) {
43-
Console.error(render("书源规则初始化失败,请检查配置项 source-id 是否正确", "red"));
44-
Console.error(render("错误信息:{}", "red"), e.getMessage());
43+
Console.error(render("书源规则初始化失败,请检查配置项 source-id 是否正确。{}", "red"), e.getMessage());
4544
System.exit(1);
4645
}
4746

src/main/java/com/pcdd/sonovel/handle/EpubMergeHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class EpubMergeHandler implements PostProcessingHandler {
3030
@Override
3131
public void handle(Book b, File savePath) {
3232
if (FileUtil.isDirEmpty(savePath)) {
33-
Console.error(render("==> 《{}》({})下载章节数为 0,取消生成 EPUB", "red"), b.getBookName(), b.getAuthor());
33+
Console.error(render("<== 《{}》({})下载章节数为 0,取消生成 EPUB", "red"), b.getBookName(), b.getAuthor());
3434
return;
3535
}
3636

src/main/java/com/pcdd/sonovel/parse/ChapterParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ private Chapter retry(Chapter chapter, SearchResult sr) {
6868
for (int attempt = 1; attempt <= config.getMaxRetryAttempts(); attempt++) {
6969
try {
7070
long interval = CrawlUtils.randomInterval(config, true);
71-
Console.log(render("==> 章节下载失败,正在重试: 【{}】 重试次数: {}/{} 重试间隔: {} ms", "red"),
71+
Console.log(render("<== 章节下载失败,正在重试: 【{}】 重试次数: {}/{} 重试间隔: {} ms", "red"),
7272
chapter.getTitle(), attempt, config.getMaxRetryAttempts(), interval);
7373
chapter.setContent(crawl(chapter.getUrl(), interval));
7474
Console.log(render("<== 重试成功: 【{}】", "green"), chapter.getTitle());
7575
return chapterConverter.convert(chapter);
7676

7777
} catch (Exception e) {
78-
Console.error(render("==> 第 {} 次重试失败: 【{}】 原因: {}", "red"), attempt, chapter.getTitle(), e.getMessage());
78+
Console.error(render("<== 第 {} 次重试失败: 【{}】 原因: {}", "red"), attempt, chapter.getTitle(), e.getMessage());
7979
if (attempt == config.getMaxRetryAttempts()) {
8080
// 最终失败时记录日志
8181
saveErrorLog(chapter, sr, e.getMessage());

src/main/java/com/pcdd/sonovel/parse/SearchParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public List<SearchResult> parse(String keyword) {
4949
Rule.Search r = this.rule.getSearch();
5050

5151
if (r == null) {
52-
Console.log("书源 {} 不支持搜索", config.getSourceId());
52+
Console.log(render("<== 书源 {} 不支持搜索", "red"), config.getSourceId());
5353
return Collections.emptyList();
5454
}
5555

5656
if (this.rule.isDisabled()) {
57-
Console.error("书源 {} 暂被禁用!", this.rule.getId());
57+
Console.error(render("<== 书源 {} 暂被禁用!", "red"), this.rule.getId());
5858
return Collections.emptyList();
5959
}
6060

@@ -66,7 +66,7 @@ public List<SearchResult> parse(String keyword) {
6666
.execute();
6767
document = Jsoup.parse(resp.body());
6868
} catch (Exception e) {
69-
Console.error(render("书源 {} 搜索解析出错: {}", "red"), this.rule.getId(), e.getMessage());
69+
Console.error(render("<== 书源 {} 搜索解析出错: {}", "red"), this.rule.getId(), e.getMessage());
7070
return Collections.emptyList();
7171
}
7272

0 commit comments

Comments
 (0)