@@ -21,35 +21,84 @@ void loggerPrint(String level, String message, Optilog instance) {
21
21
22
22
@ OnlyInLog
23
23
void loggerConsole (String level , String message , Optilog instance ) {
24
- synchronized (Send .INSTANCE ) {
25
- try {
26
- if (instance .consoleFileMasterCaution && Level .INFO .getName ().equals (level ) && !instance .info .isBlank ()) {
27
- Files .writeString (Path .of (instance .info ), Files .readString (Path .of (instance .info ), StandardCharsets .UTF_8 ) + Packing .packMessage (message , level , instance ), StandardCharsets .UTF_8 );
28
- }
29
- if (instance .consoleFileMasterCaution && Level .ERROR .getName ().equals (level ) && !instance .error .isBlank ()) {
30
- Files .writeString (Path .of (instance .error ), Files .readString (Path .of (instance .error ), StandardCharsets .UTF_8 ) + Packing .packMessage (message , level , instance ), StandardCharsets .UTF_8 );
31
- }
32
- if (instance .consoleFileMasterCaution && Level .DEBUG .getName ().equals (level ) && !instance .debug .isBlank ()) {
33
- Files .writeString (Path .of (instance .debug ), Files .readString (Path .of (instance .debug ), StandardCharsets .UTF_8 ) + Packing .packMessage (message , level , instance ), StandardCharsets .UTF_8 );
34
- }
35
- if (instance .consoleFileMasterCaution && Level .WARN .getName ().equals (level ) && !instance .warn .isBlank ()) {
36
- Files .writeString (Path .of (instance .warn ), Files .readString (Path .of (instance .warn ), StandardCharsets .UTF_8 ) + Packing .packMessage (message , level , instance ), StandardCharsets .UTF_8 );
37
- }
38
- if (instance .consoleFileMasterCaution && Level .FATAL .getName ().equals (level ) && !instance .fatal .isBlank ()) {
39
- Files .writeString (Path .of (instance .fatal ), Files .readString (Path .of (instance .fatal ), StandardCharsets .UTF_8 ) + Packing .packMessage (message , level , instance ), StandardCharsets .UTF_8 );
40
- }
41
- } catch (RuntimeException | IOException e ) {
42
- instance .consoleFileMasterCaution = false ;
43
- instance .error ("Optilog Note:Java throws Exception when log is output" , e );
24
+ try {
25
+ if (instance .consoleFileMasterCaution && Level .INFO .getName ().equals (level ) && !instance .info .isBlank ()) {
26
+ String s = Packing .packMessage (message , level , instance );
27
+ instance .logThread .submit (() -> {
28
+ try {
29
+ synchronized (Send .INSTANCE ) {
30
+ Files .writeString (Path .of (instance .info ), Files .readString (Path .of (instance .info ), StandardCharsets .UTF_8 ) + s , StandardCharsets .UTF_8 );
31
+ }
32
+ } catch (IOException e ) {
33
+ instance .consoleFileMasterCaution = false ;
34
+ instance .error ("Optilog Note:Java throws Exception when log is output" , e );
35
+ }
36
+ });
37
+ }
38
+ if (instance .consoleFileMasterCaution && Level .ERROR .getName ().equals (level ) && !instance .error .isBlank ()) {
39
+ String s = Packing .packMessage (message , level , instance );
40
+ instance .logThread .submit (() -> {
41
+ try {
42
+ synchronized (Send .INSTANCE ) {
43
+ Files .writeString (Path .of (instance .error ), Files .readString (Path .of (instance .error ), StandardCharsets .UTF_8 ) + s , StandardCharsets .UTF_8 );
44
+ }
45
+ } catch (IOException e ) {
46
+ instance .consoleFileMasterCaution = false ;
47
+ instance .error ("Optilog Note:Java throws Exception when log is output" , e );
48
+ }
49
+ });
50
+ }
51
+ if (instance .consoleFileMasterCaution && Level .DEBUG .getName ().equals (level ) && !instance .debug .isBlank ()) {
52
+ String s = Packing .packMessage (message , level , instance );
53
+ instance .logThread .submit (() -> {
54
+ try {
55
+ synchronized (Send .INSTANCE ) {
56
+ Files .writeString (Path .of (instance .debug ), Files .readString (Path .of (instance .debug ), StandardCharsets .UTF_8 ) + s , StandardCharsets .UTF_8 );
57
+ }
58
+ } catch (IOException e ) {
59
+ instance .consoleFileMasterCaution = false ;
60
+ instance .error ("Optilog Note:Java throws Exception when log is output" , e );
61
+ }
62
+ });
63
+ }
64
+ if (instance .consoleFileMasterCaution && Level .WARN .getName ().equals (level ) && !instance .warn .isBlank ()) {
65
+ String s = Packing .packMessage (message , level , instance );
66
+ instance .logThread .submit (() -> {
67
+ try {
68
+ synchronized (Send .INSTANCE ) {
69
+ Files .writeString (Path .of (instance .warn ), Files .readString (Path .of (instance .warn ), StandardCharsets .UTF_8 ) + s , StandardCharsets .UTF_8 );
70
+ }
71
+ } catch (IOException e ) {
72
+ instance .consoleFileMasterCaution = false ;
73
+ instance .error ("Optilog Note:Java throws Exception when log is output" , e );
74
+ }
75
+ });
76
+ }
77
+ if (instance .consoleFileMasterCaution && Level .FATAL .getName ().equals (level ) && !instance .fatal .isBlank ()) {
78
+ String s = Packing .packMessage (message , level , instance );
79
+ instance .logThread .submit (() -> {
80
+ try {
81
+ synchronized (Send .INSTANCE ) {
82
+ Files .writeString (Path .of (instance .fatal ), Files .readString (Path .of (instance .fatal ), StandardCharsets .UTF_8 ) + s , StandardCharsets .UTF_8 );
83
+ }
84
+ } catch (IOException e ) {
85
+ instance .consoleFileMasterCaution = false ;
86
+ instance .error ("Optilog Note:Java throws Exception when log is output" , e );
87
+ }
88
+ });
44
89
}
90
+ } catch (RuntimeException e ) {
91
+ instance .consoleFileMasterCaution = false ;
92
+ instance .error ("Optilog Note:Java throws Exception when log is output" , e );
45
93
}
46
94
}
47
95
48
96
@ OnlyInLog
49
- void loggerToServer (String level , String message , Optilog instance ) {
97
+ void loggerToServer (final String level , String message , final Optilog instance ) {
50
98
synchronized (Send .INSTANCE ) {
51
99
message = Packing .packMessage (message , level , instance );
52
- Client .send (message + level , instance );
100
+ String finalMessage = message ;
101
+ instance .logThread .submit (() -> Client .send (finalMessage + level , instance ));
53
102
}
54
103
}
55
104
}
0 commit comments