10
10
import com .exceptionless .exceptionlessclient .models .enums .EventType ;
11
11
import com .exceptionless .exceptionlessclient .models .submission .SubmissionResponse ;
12
12
import com .exceptionless .exceptionlessclient .plugins .EventPluginRunner ;
13
+ import com .exceptionless .exceptionlessclient .utils .VisibleForTesting ;
13
14
import lombok .Builder ;
14
15
import lombok .Getter ;
15
16
import org .slf4j .Logger ;
@@ -34,10 +35,20 @@ public ExceptionlessClient(ConfigurationManager configurationManager) {
34
35
this .eventPluginRunner =
35
36
EventPluginRunner .builder ().configurationManager (this .configurationManager ).build ();
36
37
this .updateSettingsTimer = new Timer (UPDATE_SETTINGS_TIMER_NAME );
37
- init ();
38
+ init (UPDATE_SETTINGS_TIMER_INITIAL_DELAY );
38
39
}
39
40
40
- private void init () {
41
+ @ VisibleForTesting
42
+ ExceptionlessClient (
43
+ ConfigurationManager configurationManager , long updateSettingsTimerInitialDelay ) {
44
+ this .configurationManager = configurationManager ;
45
+ this .eventPluginRunner =
46
+ EventPluginRunner .builder ().configurationManager (this .configurationManager ).build ();
47
+ this .updateSettingsTimer = new Timer (UPDATE_SETTINGS_TIMER_NAME );
48
+ init (updateSettingsTimerInitialDelay );
49
+ }
50
+
51
+ private void init (long delay ) {
41
52
updateSettingsTimer .schedule (
42
53
new TimerTask () {
43
54
@ Override
@@ -49,16 +60,15 @@ public void run() {
49
60
}
50
61
}
51
62
},
52
- UPDATE_SETTINGS_TIMER_INITIAL_DELAY ,
63
+ delay ,
53
64
configurationManager .getConfiguration ().getUpdateSettingsWhenIdleInterval ());
54
65
55
66
configurationManager .onChanged (
56
67
ignored -> configurationManager .getSettingsManager ().updateSettings ());
57
68
configurationManager
58
69
.getQueue ()
59
70
.onEventsPosted (
60
- (ignored1 , ignored2 ) ->
61
- configurationManager .getSettingsManager ().updateSettings ());
71
+ (ignored1 , ignored2 ) -> configurationManager .getSettingsManager ().updateSettings ());
62
72
}
63
73
64
74
public static ExceptionlessClient from (String apiKey , String serverUrl ) {
@@ -76,7 +86,7 @@ public void submitException(Exception exception) {
76
86
submitEvent (EventPluginContext .builder ().event (event ).context (pluginContext ).build ());
77
87
}
78
88
79
- private Event .EventBuilder createException () {
89
+ public Event .EventBuilder createException () {
80
90
return createEvent ().type (EventType .ERROR .value ());
81
91
}
82
92
@@ -96,7 +106,7 @@ public void submitFeatureUsage(String feature) {
96
106
submitEvent (EventPluginContext .from (event ));
97
107
}
98
108
99
- private Event .EventBuilder createFeatureUsage (String feature ) {
109
+ public Event .EventBuilder createFeatureUsage (String feature ) {
100
110
return createEvent ().type (EventType .USAGE .value ()).source (feature );
101
111
}
102
112
@@ -113,10 +123,23 @@ public void submitLog(String message, String source, String level) {
113
123
submitEvent (EventPluginContext .from (event ));
114
124
}
115
125
116
- private Event .EventBuilder createLog (String message , String source , String level ) {
126
+ public Event .EventBuilder createLog (String message ) {
127
+ return createLog (message , null , null );
128
+ }
129
+
130
+ public Event .EventBuilder createLog (String message , String source ) {
131
+ return createLog (message , source , null );
132
+ }
133
+
134
+ public Event .EventBuilder createLog (String message , String source , String level ) {
117
135
if (source == null ) {
118
136
// Calling method
119
- source = Thread .currentThread ().getStackTrace ()[2 ].getMethodName ();
137
+ StackTraceElement [] traceElements = Thread .currentThread ().getStackTrace ();
138
+ source = traceElements [2 ].getMethodName ();
139
+ // Came from the overrided method
140
+ if (source .equals ("createLog" )) {
141
+ source = traceElements [3 ].getMethodName ();
142
+ }
120
143
}
121
144
122
145
Event .EventBuilder builder =
@@ -133,7 +156,7 @@ public void submitNotFound(String resource) {
133
156
submitEvent (EventPluginContext .from (event ));
134
157
}
135
158
136
- private Event .EventBuilder createNotFound (String resource ) {
159
+ public Event .EventBuilder createNotFound (String resource ) {
137
160
return createEvent ().type (EventType .NOT_FOUND .value ()).source (resource );
138
161
}
139
162
@@ -142,11 +165,11 @@ public void submitSessionStart() {
142
165
submitEvent (EventPluginContext .from (event ));
143
166
}
144
167
145
- private Event .EventBuilder createSessionStart () {
168
+ public Event .EventBuilder createSessionStart () {
146
169
return createEvent ().type (EventType .SESSION .value ());
147
170
}
148
171
149
- private Event .EventBuilder createEvent () {
172
+ public Event .EventBuilder createEvent () {
150
173
return Event .builder ()
151
174
.dataExclusions (configurationManager .getDataExclusions ())
152
175
.date (LocalDate .now ());
0 commit comments