Skip to content

Commit 1f90b98

Browse files
committed
2022.6-Client(performance)
1 parent 82006c1 commit 1f90b98

36 files changed

+93
-79
lines changed
Binary file not shown.
Binary file not shown.

.gradle/7.4/fileHashes/fileHashes.bin

500 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
13.5 KB
Binary file not shown.
Binary file not shown.

.gradle/file-system.probe

0 Bytes
Binary file not shown.

README-en.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Optilog
2+
23
![Build](https://img.shields.io/badge/Build-Passing-green)
34
[![Latest-Release](https://img.shields.io/badge/Release-Latest-blue)](https://github.com/OptiJava/Optilog-Client/releases/latest)
45
[![Languege](https://img.shields.io/badge/Language-ChinesePage-red)](https://github.com/OptiJava/Optilog-Client/blob/master/README.md)
@@ -22,8 +23,9 @@ will be a bug! (see wiki for details)(expect when you need change setting file)
2223

2324
# Optilog advantages
2425

25-
1.High performance: Initialization log + output a log (output to the screen + output to a file + output to the server
26-
through socket) only takes 130 milliseconds at most (it will be optimized later), and log4j takes at least 300
26+
1.High performance: After initialization log, output a log (output to the screen + output to a file + output to the
27+
server
28+
through socket) only takes 8 milliseconds at most (it will be optimized later), and log4j takes at least 41
2729
milliseconds.
2830

2931
2.Optilog supports unlimited placeholders and can be reused (#1 #1 outputs the first placeholder twice). Log4j only

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# [Optilog-Client](https://github.com/OptiJava/Optilog-Client/)
2+
23
![Build](https://img.shields.io/badge/Build-Passing-green)
34
[![Latest-Release](https://img.shields.io/badge/Release-Latest-blue)](https://github.com/OptiJava/Optilog-Client/releases/latest)
45
[![Languege](https://img.shields.io/badge/Language-EnglishPage-red)](https://github.com/OptiJava/Optilog-Client/blob/master/README-en.md)
@@ -21,7 +22,7 @@ _如果你愿意,欢迎Fork这个仓库为Optilog做出贡献,本项目的
2122

2223
# Optilog的优势
2324

24-
1.性能高:初始化日志+输出一条日志(输出到屏幕+输出到文件+通过socket输出到服务端) 最快只需要130毫秒(后续还会再优化),log4j至少300毫秒
25+
1.性能高:在初始化后,再输出一条日志(输出到屏幕+输出到文件+通过socket输出到服务端) 最快只需要8毫秒(后续还会再优化),log4j至少41毫秒
2526

2627
2.占位符方便:Optilog支持无限个占位符,并且可以重复使用(#1 #1输出两次第一个占位符),log4j只支持9个占位符
2728

@@ -58,7 +59,8 @@ _如果你愿意,欢迎Fork这个仓库为Optilog做出贡献,本项目的
5859

5960
# Dependency:
6061

61-
`Gson-2.9.0` `jackson-dataformat-xml-2.13.3` `tomcat-embed-core-9.0.26` `tomcat-embed-jasper:9.0.26`(Tomcat依赖如果你不用的话可以没有,如果你只用properties作为配置文件的话Gson和Jackson也可以不加)
62+
`Gson-2.9.0` `jackson-dataformat-xml-2.13.3` `tomcat-embed-core-9.0.26` `tomcat-embed-jasper:9.0.26`(
63+
Tomcat依赖如果你不用的话可以没有,如果你只用properties作为配置文件的话Gson和Jackson也可以不加)
6264

6365
# Author:
6466

176 Bytes
Binary file not shown.
Binary file not shown.
-241 Bytes
Binary file not shown.
Binary file not shown.
111 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
printInfo=true
2+
printError=true
3+
printWarn=true
4+
printDebug=true
5+
printFatal=true
6+
defaultConsolePath=
7+
#Path1=
8+
#Path2=
9+
#infoPath=%path1
10+
#errorPath=%path2
11+
#warnPath=%path1
12+
#debugPath=%path1
13+
#fatalPath=%path2
14+
consoleInfo=false
15+
consoleDebug=false
16+
consoleError=false
17+
consoleWarn=false
18+
consoleFatal=false
19+
infoSendToServer=false
20+
errorSendToServer=false
21+
warnSendToServer=false
22+
debugSendToServer=false
23+
fatalSendToServer=false
24+
startClient=false
25+
socketNumber=65535
26+
packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg
27+
fileName=%timeLog.log
28+
host=localhost
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[2022-06-04|15:06:57(20))][com.optilog.PerformanceTester main(PerformanceTester.java:8)/main] info:
2+
[2022-06-04|15:06:57(23))][com.optilog.PerformanceTester main(PerformanceTester.java:11)/main] info:
Binary file not shown.
Binary file not shown.

src/main/java/com/optilog/log/Log.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
public interface Log {
66
static Optilog initLog(String pathOfSettingFile) {
7-
return new Optilog(pathOfSettingFile);
7+
Optilog optilog = new Optilog(pathOfSettingFile);
8+
LogInit.initLog(pathOfSettingFile, optilog);
9+
return optilog;
810
}
911

1012
static Optilog reInitLog(String pathOfSettingFile) {
11-
return new Optilog(pathOfSettingFile);
13+
Optilog optilog = new Optilog(pathOfSettingFile);
14+
LogInit.initLog(pathOfSettingFile, optilog);
15+
return optilog;
1216
}
1317

1418
void info();

src/main/java/com/optilog/log/LogInit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ private LogInit() {
1616
public static void initLog(String settingFilePath, Optilog instance) {
1717
if (settingFilePath.isBlank()) {
1818
instance.consoleFileMasterCaution = false;
19-
instance.allSetting = new SettingFiles();
2019
}
20+
instance.allSetting = new SettingFiles();
2121

2222
try {
2323
SettingFiles.check(settingFilePath, instance);

src/main/java/com/optilog/log/Logger.java

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ private Logger() {
1313

1414
@OnlyInLog
1515
void logInfo(LogEvent le, Optilog instance) {
16-
if (!instance.alreadyInit) {
17-
LogInit.initLog(instance.settingFilePath, instance);
18-
instance.alreadyInit = true;
19-
}
20-
2116
if (instance.allSetting.printInfo) {
2217
Send.INSTANCE.loggerPrint(le, instance);
2318
}
@@ -26,17 +21,13 @@ void logInfo(LogEvent le, Optilog instance) {
2621
Send.INSTANCE.loggerConsole(le, instance);
2722
}
2823

29-
if (instance.allSetting.serverInfo & instance.allSetting.startClient) {
24+
if (instance.consoleFileMasterCaution & instance.allSetting.serverInfo & instance.allSetting.startClient) {
3025
Send.INSTANCE.loggerToServer(le, instance);
3126
}
3227
}
3328

3429
@OnlyInLog
3530
void logError(LogEvent le, Optilog instance) {
36-
if (!instance.alreadyInit) {
37-
LogInit.initLog(instance.settingFilePath, instance);
38-
instance.alreadyInit = true;
39-
}
4031
if (instance.allSetting.printError) {
4132
Send.INSTANCE.loggerPrint(le, instance);
4233
}
@@ -45,17 +36,13 @@ void logError(LogEvent le, Optilog instance) {
4536
Send.INSTANCE.loggerConsole(le, instance);
4637
}
4738

48-
if (instance.allSetting.serverError & instance.allSetting.startClient) {
39+
if (instance.consoleFileMasterCaution & instance.allSetting.serverError & instance.allSetting.startClient) {
4940
Send.INSTANCE.loggerToServer(le, instance);
5041
}
5142
}
5243

5344
@OnlyInLog
5445
void logWarn(LogEvent le, Optilog instance) {
55-
if (!instance.alreadyInit) {
56-
LogInit.initLog(instance.settingFilePath, instance);
57-
instance.alreadyInit = true;
58-
}
5946
if (instance.allSetting.printWarn) {
6047
Send.INSTANCE.loggerPrint(le, instance);
6148
}
@@ -64,17 +51,13 @@ void logWarn(LogEvent le, Optilog instance) {
6451
Send.INSTANCE.loggerConsole(le, instance);
6552
}
6653

67-
if (instance.allSetting.serverWarn & instance.allSetting.startClient) {
54+
if (instance.consoleFileMasterCaution & instance.allSetting.serverWarn & instance.allSetting.startClient) {
6855
Send.INSTANCE.loggerToServer(le, instance);
6956
}
7057
}
7158

7259
@OnlyInLog
7360
void logDebug(LogEvent le, Optilog instance) {
74-
if (!instance.alreadyInit) {
75-
LogInit.initLog(instance.settingFilePath, instance);
76-
instance.alreadyInit = true;
77-
}
7861
if (instance.allSetting.printDebug) {
7962
Send.INSTANCE.loggerPrint(le, instance);
8063
}
@@ -83,17 +66,13 @@ void logDebug(LogEvent le, Optilog instance) {
8366
Send.INSTANCE.loggerConsole(le, instance);
8467
}
8568

86-
if (instance.allSetting.serverDebug & instance.allSetting.startClient) {
69+
if (instance.consoleFileMasterCaution & instance.allSetting.serverDebug & instance.allSetting.startClient) {
8770
Send.INSTANCE.loggerToServer(le, instance);
8871
}
8972
}
9073

9174
@OnlyInLog
9275
void logFatal(LogEvent le, Optilog instance) {
93-
if (!instance.alreadyInit) {
94-
LogInit.initLog(instance.settingFilePath, instance);
95-
instance.alreadyInit = true;
96-
}
9776
if (instance.allSetting.printFatal) {
9877
Send.INSTANCE.loggerPrint(le, instance);
9978
}
@@ -102,7 +81,7 @@ void logFatal(LogEvent le, Optilog instance) {
10281
Send.INSTANCE.loggerConsole(le, instance);
10382
}
10483

105-
if (instance.allSetting.serverFatal & instance.allSetting.startClient) {
84+
if (instance.consoleFileMasterCaution & instance.allSetting.serverFatal & instance.allSetting.startClient) {
10685
Send.INSTANCE.loggerToServer(le, instance);
10786
}
10887
}

src/main/java/com/optilog/log/Optilog.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
public class Optilog implements Log {
1313
public volatile DatagramSocket socket;
1414
public volatile boolean consoleFileMasterCaution = true;
15-
public volatile boolean alreadyInit;
1615

1716
public volatile SettingFiles allSetting;
1817

@@ -27,7 +26,6 @@ public class Optilog implements Log {
2726
@OnlyInInit
2827
Optilog(String var1) {
2928
this.settingFilePath = var1;
30-
this.alreadyInit = false;
3129
}
3230

3331
@Override

src/main/java/com/optilog/log/console/Console.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@ public class Console {
1313
@OnlyInInit
1414
public static void initAppender(Optilog instance) {
1515
if (instance.consoleFileMasterCaution) {
16-
if (instance.allSetting != null) {
17-
instance.allSetting.fileName = instance.allSetting.fileName.replace("%time", Matcher.quoteReplacement(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss").format(LocalDateTime.now())));
18-
} else {
19-
instance.consoleFileMasterCaution = false;
20-
return;
21-
}
16+
instance.allSetting.fileName = instance.allSetting.fileName.replace("%time", Matcher.quoteReplacement(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss").format(LocalDateTime.now())));
2217

2318
if (!instance.allSetting.defaultConsolePath.equals("") & instance.consoleFileMasterCaution) {
2419
final File f = new File(instance.allSetting.defaultConsolePath);
25-
if (Console.checkFile(f, instance) & instance.consoleFileMasterCaution) {
20+
if (Console.checkFile(f, instance)) {
2621
File defFile = new File(instance.allSetting.defaultConsolePath + "//" + instance.allSetting.fileName);
2722
try {
2823
if (!defFile.isFile()) {

src/main/java/com/optilog/setting/PropSettings.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ static void properties(InputStream content, Optilog instance) {
1313
final Properties p = new Properties();
1414
try {
1515
p.load(content);
16-
instance.allSetting = new SettingFiles();
1716

1817
instance.allSetting.printInfo = Boolean.parseBoolean(p.getProperty("printInfo", "true"));
1918
instance.allSetting.printError = Boolean.parseBoolean(p.getProperty("printError", "true"));

src/main/java/com/optilog/setting/SettingFiles.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.optilog.log.Optilog;
55
import com.optilog.util.OnlyInInit;
66
import com.optilog.util.exception.ConfigureException;
7-
import com.optilog.util.exception.GsonNotFoundException;
87

98
import java.io.File;
109
import java.io.FileInputStream;
@@ -53,24 +52,6 @@ public class SettingFiles {
5352

5453
@OnlyInInit
5554
public static void check(String str, Optilog instance) throws IOException {
56-
try {
57-
Class.forName("com.google.gson.Gson");
58-
} catch (ClassNotFoundException e) {
59-
if (!str.isBlank()) {
60-
System.err.println("Can't find Gson in classpath");
61-
instance.consoleFileMasterCaution = false;
62-
throw new GsonNotFoundException("Can't found Gson in classpath", new ClassNotFoundException("Class:com.google.gson.Gson not found"));
63-
}
64-
}
65-
try {
66-
Class.forName("com.fasterxml.jackson.dataformat.xml.JacksonXmlModule");
67-
} catch (ClassNotFoundException e) {
68-
if (!str.isBlank()) {
69-
System.err.println("Can't find jackson in classpath");
70-
instance.consoleFileMasterCaution = false;
71-
throw new GsonNotFoundException("Can't found jackson in classpath", new ClassNotFoundException("Class:com.fasterxml.jackson.dataformat.xml.JacksonXmlModule not found"));
72-
}
73-
}
7455
if (!str.isBlank()) {
7556
if (str.startsWith("%xml -cp ")) {
7657
XmlSettings.xml(str.substring(9), true, instance);
@@ -125,10 +106,6 @@ private static void getSetting(String s, Optilog instance, boolean isClasspath)
125106
System.exit(1);
126107
}
127108

128-
if (instance.allSetting == null) {
129-
instance.allSetting = new SettingFiles();
130-
}
131-
132109
if (object.defaultConsolePath != null) {
133110
instance.allSetting.defaultConsolePath = object.defaultConsolePath;
134111
}

src/main/java/com/optilog/setting/XmlSettings.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ static void xml(String path, boolean isClasspath, Optilog instance) {
2121
}
2222
Settings object = new XmlMapper(new JacksonXmlModule()).readValue(input, Settings.class);
2323

24-
if (instance.allSetting == null) {
25-
instance.allSetting = new SettingFiles();
26-
}
27-
2824
if (object.defaultConsolePath != null) {
2925
instance.allSetting.defaultConsolePath = object.defaultConsolePath.trim();
3026
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.optilog;
22

33
public class JavaTest {
4-
public static void main(String[] args) {
5-
6-
}
4+
public static void main(String[] args) {
5+
6+
}
77
}

src/test/java/com/optilog/PerformanceTester.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import com.optilog.log.Log;
44

55
public class PerformanceTester {
6-
public static void main(String[] args) {
7-
long l = System.currentTimeMillis();
8-
Log log = Log.initLog("%prop -cp /Settings.properties");
9-
log.info("");
10-
System.out.println(System.currentTimeMillis() - l);
11-
}
6+
public static void main(String[] args) {
7+
long l = System.currentTimeMillis();
8+
Log log = Log.initLog("%prop -cp /MinSetting.properties");
9+
log.info();
10+
11+
12+
System.out.println(System.currentTimeMillis() - l);
13+
}
1214
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
printInfo=true
2+
printError=true
3+
printWarn=true
4+
printDebug=true
5+
printFatal=true
6+
defaultConsolePath=
7+
#Path1=
8+
#Path2=
9+
#infoPath=%path1
10+
#errorPath=%path2
11+
#warnPath=%path1
12+
#debugPath=%path1
13+
#fatalPath=%path2
14+
consoleInfo=false
15+
consoleDebug=false
16+
consoleError=false
17+
consoleWarn=false
18+
consoleFatal=false
19+
infoSendToServer=false
20+
errorSendToServer=false
21+
warnSendToServer=false
22+
debugSendToServer=false
23+
fatalSendToServer=false
24+
startClient=false
25+
socketNumber=65535
26+
packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg
27+
fileName=%timeLog.log
28+
host=localhost
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[2022-06-04|15:06:57(20))][com.optilog.PerformanceTester main(PerformanceTester.java:8)/main] info:
2+
[2022-06-04|15:06:57(23))][com.optilog.PerformanceTester main(PerformanceTester.java:11)/main] info:

0 commit comments

Comments
 (0)