1010import com .exceptionless .exceptionlessclient .models .enums .EventType ;
1111import com .exceptionless .exceptionlessclient .models .submission .SubmissionResponse ;
1212import com .exceptionless .exceptionlessclient .plugins .EventPluginRunner ;
13+ import com .exceptionless .exceptionlessclient .utils .VisibleForTesting ;
1314import lombok .Builder ;
1415import lombok .Getter ;
1516import org .slf4j .Logger ;
@@ -34,10 +35,20 @@ public ExceptionlessClient(ConfigurationManager configurationManager) {
3435 this .eventPluginRunner =
3536 EventPluginRunner .builder ().configurationManager (this .configurationManager ).build ();
3637 this .updateSettingsTimer = new Timer (UPDATE_SETTINGS_TIMER_NAME );
37- init ();
38+ init (UPDATE_SETTINGS_TIMER_INITIAL_DELAY );
3839 }
3940
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 ) {
4152 updateSettingsTimer .schedule (
4253 new TimerTask () {
4354 @ Override
@@ -49,16 +60,15 @@ public void run() {
4960 }
5061 }
5162 },
52- UPDATE_SETTINGS_TIMER_INITIAL_DELAY ,
63+ delay ,
5364 configurationManager .getConfiguration ().getUpdateSettingsWhenIdleInterval ());
5465
5566 configurationManager .onChanged (
5667 ignored -> configurationManager .getSettingsManager ().updateSettings ());
5768 configurationManager
5869 .getQueue ()
5970 .onEventsPosted (
60- (ignored1 , ignored2 ) ->
61- configurationManager .getSettingsManager ().updateSettings ());
71+ (ignored1 , ignored2 ) -> configurationManager .getSettingsManager ().updateSettings ());
6272 }
6373
6474 public static ExceptionlessClient from (String apiKey , String serverUrl ) {
@@ -76,7 +86,7 @@ public void submitException(Exception exception) {
7686 submitEvent (EventPluginContext .builder ().event (event ).context (pluginContext ).build ());
7787 }
7888
79- private Event .EventBuilder createException () {
89+ public Event .EventBuilder createException () {
8090 return createEvent ().type (EventType .ERROR .value ());
8191 }
8292
@@ -96,7 +106,7 @@ public void submitFeatureUsage(String feature) {
96106 submitEvent (EventPluginContext .from (event ));
97107 }
98108
99- private Event .EventBuilder createFeatureUsage (String feature ) {
109+ public Event .EventBuilder createFeatureUsage (String feature ) {
100110 return createEvent ().type (EventType .USAGE .value ()).source (feature );
101111 }
102112
@@ -113,10 +123,23 @@ public void submitLog(String message, String source, String level) {
113123 submitEvent (EventPluginContext .from (event ));
114124 }
115125
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 ) {
117135 if (source == null ) {
118136 // 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+ }
120143 }
121144
122145 Event .EventBuilder builder =
@@ -133,7 +156,7 @@ public void submitNotFound(String resource) {
133156 submitEvent (EventPluginContext .from (event ));
134157 }
135158
136- private Event .EventBuilder createNotFound (String resource ) {
159+ public Event .EventBuilder createNotFound (String resource ) {
137160 return createEvent ().type (EventType .NOT_FOUND .value ()).source (resource );
138161 }
139162
@@ -142,11 +165,11 @@ public void submitSessionStart() {
142165 submitEvent (EventPluginContext .from (event ));
143166 }
144167
145- private Event .EventBuilder createSessionStart () {
168+ public Event .EventBuilder createSessionStart () {
146169 return createEvent ().type (EventType .SESSION .value ());
147170 }
148171
149- private Event .EventBuilder createEvent () {
172+ public Event .EventBuilder createEvent () {
150173 return Event .builder ()
151174 .dataExclusions (configurationManager .getDataExclusions ())
152175 .date (LocalDate .now ());
0 commit comments