pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/code4everything/wetool/commit/7f33dee9283b5a73b614360abe84fa9edcd49cd8

" /> feat: optimize log format · code4everything/wetool@7f33dee · GitHub
Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 7f33dee

Browse files
committed
feat: optimize log format
1 parent 187c264 commit 7f33dee

File tree

7 files changed

+55
-11
lines changed

7 files changed

+55
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ private void listenKeyboard() {
391391

392392
@Override
393393
public void start(Stage stage) {
394+
Thread.currentThread().setName("javafx");
394395
log.info("starting javafx stage");
395396
BeanFactory.register(stage);
396397

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.code4everything.wetool.logback;
2+
3+
import ch.qos.logback.classic.pattern.ClassicConverter;
4+
import ch.qos.logback.classic.spi.ILoggingEvent;
5+
import cn.hutool.core.comparator.ComparatorChain;
6+
import org.code4everything.wetool.plugin.support.exception.PluginException;
7+
8+
import java.util.Map;
9+
import java.util.Map.Entry;
10+
import java.util.TreeMap;
11+
12+
/**
13+
* @author pantao
14+
* @since 2021/6/8
15+
*/
16+
public class AppNameConverter extends ClassicConverter {
17+
18+
private static final Map<String, String> PLUGIN_NAME_MAP = new TreeMap<>(ComparatorChain.of((o1, o2) -> o2.split("\\.").length - o1.split("\\.").length, String::compareTo));
19+
20+
static {
21+
PLUGIN_NAME_MAP.put("org.code4everything.wetool", "wetool");
22+
}
23+
24+
public static void putName(String packageName, String appName) {
25+
if (PLUGIN_NAME_MAP.containsKey(packageName)) {
26+
throw new PluginException("包已存在:" + packageName);
27+
}
28+
PLUGIN_NAME_MAP.put(packageName, appName);
29+
}
30+
31+
@Override
32+
public String convert(ILoggingEvent iLoggingEvent) {
33+
String loggerName = iLoggingEvent.getLoggerName();
34+
for (Entry<String, String> entry : PLUGIN_NAME_MAP.entrySet()) {
35+
if (loggerName.startsWith(entry.getKey())) {
36+
return entry.getValue();
37+
}
38+
}
39+
return "wetool";
40+
}
41+
}

src/main/java/org/code4everything/wetool/logback/ExtendedPatternLayoutEncoder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ExtendedPatternLayoutEncoder extends PatternLayoutEncoder {
1515
public void start() {
1616
log.info("register logback pid converter");
1717
PatternLayout.defaultConverterMap.put("pid", PidConverter.class.getName());
18+
PatternLayout.defaultConverterMap.put("app", AppNameConverter.class.getName());
1819
super.start();
1920
}
2021
}

src/main/java/org/code4everything/wetool/logback/PidConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
*/
1111
public class PidConverter extends ClassicConverter {
1212

13-
private static final String pid = String.valueOf(WeUtils.getCurrentPid());
13+
private static final String PID = String.valueOf(WeUtils.getCurrentPid());
1414

1515
@Override
1616
public String convert(ILoggingEvent iLoggingEvent) {
17-
return pid;
17+
return PID;
1818
}
1919
}

src/main/java/org/code4everything/wetool/plugin/PluginLoader.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import org.code4everything.wetool.WeApplication;
2727
import org.code4everything.wetool.constant.FileConsts;
2828
import org.code4everything.wetool.controller.MainController;
29+
import org.code4everything.wetool.logback.AppNameConverter;
2930
import org.code4everything.wetool.plugin.support.WePluginSupporter;
30-
import org.code4everything.wetool.plugin.support.config.WeConfig;
3131
import org.code4everything.wetool.plugin.support.config.WePluginConfig;
3232
import org.code4everything.wetool.plugin.support.config.WePluginInfo;
3333
import org.code4everything.wetool.plugin.support.constant.AppConsts;
@@ -58,8 +58,6 @@ public final class PluginLoader {
5858

5959
private static final Set<WePlugin> LOADED_PLUGINS = new ConcurrentHashSet<>();
6060

61-
private static final WeConfig CONFIG = WeUtils.getConfig();
62-
6361
private static final Map<String, WePlugin> PREPARED_PLUGINS = new ConcurrentHashMap<>();
6462

6563
private static final Set<String> ALREADY_ADD_TAB_NAME = new ConcurrentHashSet<>();
@@ -266,16 +264,18 @@ private static void loadPluginFromPrepared() {
266264
Iterator<Map.Entry<String, WePlugin>> iterator = PREPARED_PLUGINS.entrySet().iterator();
267265
while (iterator.hasNext()) {
268266
WePlugin plugin = iterator.next().getValue();
267+
WePluginInfo pluginInfo = plugin.getPluginInfo();
269268
log.info("loading plugin from prepared: {}", plugin.toJsonString());
270269
try {
271270
// 加载插件类
272271
plugin.getClassLoader().addJar(plugin.getJarFile());
273-
Class<?> clazz = plugin.getClassLoader().loadClass(plugin.getPluginInfo().getSupportedClass());
272+
Class<?> clazz = plugin.getClassLoader().loadClass(pluginInfo.getSupportedClass());
274273
WePluginSupporter supporter = (WePluginSupporter) ReflectUtil.newInstance(clazz);
275274
// 添加插件菜单
276-
if (registerPlugin(plugin.getPluginInfo(), supporter)) {
275+
if (registerPlugin(pluginInfo, supporter)) {
277276
LOADED_PLUGINS.add(plugin);
278277
}
278+
AppNameConverter.putName(supporter.getClass().getPackageName(), pluginInfo.getAuthor() + "-" + pluginInfo.getName());
279279
} catch (Exception e) {
280280
FxDialogs.showException("plugin file load failed: " + plugin.getJarFile().getName(), e);
281281
}
@@ -301,7 +301,8 @@ private static boolean isIncompatible(WePluginInfo info) {
301301
}
302302

303303
private static boolean isDisabled(WePluginInfo pluginInfo) {
304-
for (WePluginInfo disableInfo : CONFIG.getPluginDisables()) {
304+
Set<WePluginInfo> pluginDisables = WeUtils.getConfig().getPluginDisables();
305+
for (WePluginInfo disableInfo : pluginDisables) {
305306
// @formatter:off
306307
boolean disabled = (StrUtil.isEmpty(disableInfo.getAuthor()) || disableInfo.getAuthor().equals(pluginInfo.getAuthor()))
307308
&& (StrUtil.isEmpty(disableInfo.getName()) || disableInfo.getName().equals(pluginInfo.getName()))

src/main/resources/logback.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
<totalSizeCap>1GB</totalSizeCap>
88
</rollingPolicy>
99
<encoder class="org.code4everything.wetool.logback.ExtendedPatternLayoutEncoder">
10-
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%pid] [%thread] %5p %c{0}:%L - %m%n</pattern>
10+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%pid] [%app] [%thread] %5p %c{0}:%L - %m%n</pattern>
1111
<charset class="java.nio.charset.Charset">UTF-8</charset>
1212
</encoder>
1313
</appender>
1414

1515
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
1616
<encoder class="org.code4everything.wetool.logback.ExtendedPatternLayoutEncoder">
17-
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%pid] [%thread] %5p %c{0}:%L - %m%n</pattern>
17+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%pid] [%app] [%thread] %5p %c{0}:%L - %m%n</pattern>
1818
</encoder>
1919
</appender>
2020

src/test/resources/logback-test.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<configuration>
22
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
33
<encoder class="org.code4everything.wetool.logback.ExtendedPatternLayoutEncoder">
4-
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%pid] [%thread] %5p %c{0}:%L - %m%n</pattern>
4+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%pid] [%app] [%thread] %5p %c{0}:%L - %m%n</pattern>
55
</encoder>
66
</appender>
77

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy