2424 */
2525public class ReportingService implements ReportAPI {
2626
27- private static final MessageSuppressingLogger MESSAGE_SUPPRESSING_LOGGER =
28- new MessageSuppressingLogger (Logger .getLogger (ReportingService .class .getCanonicalName ()),
29- 5 , TimeUnit .MINUTES );
30-
27+ // This logger is intended to be configurable in the WavefrontClient.Builder. Given that the invoker controls the
28+ // configuration, this is not a static logger.
29+ private final MessageSuppressingLogger messageSuppressingLogger ;
3130 private final String token ;
3231 private final URI uri ;
3332
@@ -36,9 +35,14 @@ public class ReportingService implements ReportAPI {
3635 private static final int BUFFER_SIZE = 4096 ;
3736 private static final int NO_HTTP_RESPONSE = -1 ;
3837
39- public ReportingService (URI uri , @ Nullable String token ) {
38+ public ReportingService (URI uri , @ Nullable String token , long reportingServiceLogSuppressTimeSeconds ) {
4039 this .uri = uri ;
4140 this .token = token ;
41+ // Setting suppress time to 0 invalidates the cache used by the message suppressing logger and doesn't log anything.
42+ // So defaulting to the minimum of 1 second.
43+ reportingServiceLogSuppressTimeSeconds = reportingServiceLogSuppressTimeSeconds <= 0 ? 1 : reportingServiceLogSuppressTimeSeconds ;
44+ this .messageSuppressingLogger = new MessageSuppressingLogger (Logger .getLogger (
45+ ReportingService .class .getCanonicalName ()), reportingServiceLogSuppressTimeSeconds , TimeUnit .SECONDS );
4246 }
4347
4448 @ Override
@@ -67,7 +71,7 @@ public int send(String format, InputStream stream) {
6771 }
6872 statusCode = urlConn .getResponseCode ();
6973 readAndClose (urlConn .getInputStream ());
70- MESSAGE_SUPPRESSING_LOGGER .reset (urlConn .getURL ().toString ());
74+ messageSuppressingLogger .reset (urlConn .getURL ().toString ());
7175 } catch (IOException ex ) {
7276 if (urlConn != null ) {
7377 return safeGetResponseCodeAndClose (urlConn );
@@ -117,7 +121,7 @@ public int sendEvent(InputStream stream) {
117121
118122 statusCode = urlConn .getResponseCode ();
119123 readAndClose (urlConn .getInputStream ());
120- MESSAGE_SUPPRESSING_LOGGER .reset (urlConn .getURL ().toString ());
124+ messageSuppressingLogger .reset (urlConn .getURL ().toString ());
121125 } catch (IOException ex ) {
122126 if (urlConn != null ) {
123127 return safeGetResponseCodeAndClose (urlConn );
@@ -131,7 +135,7 @@ private int safeGetResponseCodeAndClose(HttpURLConnection urlConn) {
131135 try {
132136 statusCode = urlConn .getResponseCode ();
133137 } catch (IOException ex ) {
134- MESSAGE_SUPPRESSING_LOGGER .log (urlConn .getURL ().toString (), Level .SEVERE ,
138+ messageSuppressingLogger .log (urlConn .getURL ().toString (), Level .SEVERE ,
135139 "Unable to obtain status code from the Wavefront service at "
136140 + urlConn .getURL ().toString () + " due to: " + ex );
137141 statusCode = NO_HTTP_RESPONSE ;
@@ -140,7 +144,7 @@ private int safeGetResponseCodeAndClose(HttpURLConnection urlConn) {
140144 try {
141145 readAndClose (urlConn .getErrorStream ());
142146 } catch (IOException ex ) {
143- MESSAGE_SUPPRESSING_LOGGER .log (urlConn .getURL ().toString (), Level .SEVERE ,
147+ messageSuppressingLogger .log (urlConn .getURL ().toString (), Level .SEVERE ,
144148 "Unable to read and close error stream from the Wavefront service at "
145149 + urlConn .getURL ().toString () + " due to: " + ex );
146150 }
0 commit comments