@@ -141,6 +141,8 @@ public class AsyncHttpClient {
141
141
private final Map <String , String > clientHeaderMap ;
142
142
private boolean isUrlEncodingEnabled = true ;
143
143
144
+ public static LogInterface log = new LogHandler ();
145
+
144
146
/**
145
147
* Creates a new AsyncHttpClient with default constructor arguments values
146
148
*/
@@ -187,17 +189,17 @@ public AsyncHttpClient(boolean fixNoHttpResponseException, int httpPort, int htt
187
189
*/
188
190
private static SchemeRegistry getDefaultSchemeRegistry (boolean fixNoHttpResponseException , int httpPort , int httpsPort ) {
189
191
if (fixNoHttpResponseException ) {
190
- Log .d (LOG_TAG , "Beware! Using the fix is insecure, as it doesn't verify SSL certificates." );
192
+ log .d (LOG_TAG , "Beware! Using the fix is insecure, as it doesn't verify SSL certificates." );
191
193
}
192
194
193
195
if (httpPort < 1 ) {
194
196
httpPort = 80 ;
195
- Log .d (LOG_TAG , "Invalid HTTP port number specified, defaulting to 80" );
197
+ log .d (LOG_TAG , "Invalid HTTP port number specified, defaulting to 80" );
196
198
}
197
199
198
200
if (httpsPort < 1 ) {
199
201
httpsPort = 443 ;
200
- Log .d (LOG_TAG , "Invalid HTTPS port number specified, defaulting to 443" );
202
+ log .d (LOG_TAG , "Invalid HTTPS port number specified, defaulting to 443" );
201
203
}
202
204
203
205
// Fix to SSL flaw in API < ICS
@@ -254,7 +256,7 @@ public void process(HttpRequest request, HttpContext context) {
254
256
for (String header : clientHeaderMap .keySet ()) {
255
257
if (request .containsHeader (header )) {
256
258
Header overwritten = request .getFirstHeader (header );
257
- Log .d (LOG_TAG ,
259
+ log .d (LOG_TAG ,
258
260
String .format ("Headers were overwritten! (%s | %s) overwrites (%s | %s)" ,
259
261
header , clientHeaderMap .get (header ),
260
262
overwritten .getName (), overwritten .getValue ())
@@ -342,6 +344,67 @@ public HttpContext getHttpContext() {
342
344
return this .httpContext ;
343
345
}
344
346
347
+ /**
348
+ * Will set logging enabled flag on underlying LogInterface instance.
349
+ * Default setting is logging enabled.
350
+ *
351
+ * @param loggingEnabled whether the logging should be enabled or not
352
+ */
353
+ public void setLoggingEnabled (boolean loggingEnabled ) {
354
+ log .setLoggingEnabled (loggingEnabled );
355
+ }
356
+
357
+ /**
358
+ * Returns logging enabled flag from underlying LogInterface instance
359
+ * Default setting is logging enabled.
360
+ *
361
+ * @return boolean whether is logging across the library currently enabled
362
+ */
363
+ public boolean isLoggingEnabled () {
364
+ return log .isLoggingEnabled ();
365
+ }
366
+
367
+ /**
368
+ * Sets log level to be used across all library default implementation
369
+ * Default setting is VERBOSE log level.
370
+ *
371
+ * @param logLevel int log level, either from LogInterface interface or from {@link android.util.Log}
372
+ */
373
+ public void setLoggingLevel (int logLevel ) {
374
+ log .setLoggingLevel (logLevel );
375
+ }
376
+
377
+ /**
378
+ * Retrieves current log level from underlying LogInterface instance.
379
+ * Default setting is VERBOSE log level.
380
+ *
381
+ * @return int log level currently in effect
382
+ */
383
+ public int getLoggingLevel () {
384
+ return log .getLoggingLevel ();
385
+ }
386
+
387
+ /**
388
+ * Will return current LogInterface used in AsyncHttpClient instance
389
+ *
390
+ * @return LogInterface currently used by AsyncHttpClient instance
391
+ */
392
+ public LogInterface getLogInterface () {
393
+ return log ;
394
+ }
395
+
396
+ /**
397
+ * Sets default LogInterface (similar to std Android Log util class) instance,
398
+ * to be used in AsyncHttpClient instance
399
+ *
400
+ * @param logInterfaceInstance LogInterface instance, if null, nothing is done
401
+ */
402
+ public void setLogInterface (LogInterface logInterfaceInstance ) {
403
+ if (logInterfaceInstance != null ) {
404
+ log = logInterfaceInstance ;
405
+ }
406
+ }
407
+
345
408
/**
346
409
* Sets an optional CookieStore to use when making requests
347
410
*
@@ -669,7 +732,7 @@ public void setBasicAuth(String username, String password, AuthScope scope, bool
669
732
670
733
public void setCredentials (AuthScope authScope , Credentials credentials ) {
671
734
if (credentials == null ) {
672
- Log .d (LOG_TAG , "Provided credentials are null, not setting" );
735
+ log .d (LOG_TAG , "Provided credentials are null, not setting" );
673
736
return ;
674
737
}
675
738
this .httpClient .getCredentialsProvider ().setCredentials (authScope == null ? AuthScope .ANY : authScope , credentials );
@@ -718,7 +781,7 @@ public void clearCredentialsProvider() {
718
781
*/
719
782
public void cancelRequests (final Context context , final boolean mayInterruptIfRunning ) {
720
783
if (context == null ) {
721
- Log .e (LOG_TAG , "Passed null Context to cancelRequests" );
784
+ log .e (LOG_TAG , "Passed null Context to cancelRequests" );
722
785
return ;
723
786
}
724
787
@@ -1304,10 +1367,10 @@ protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpCo
1304
1367
if (responseHandler .getUseSynchronousMode () && !responseHandler .getUsePoolThread ()) {
1305
1368
throw new IllegalArgumentException ("Synchronous ResponseHandler used in AsyncHttpClient. You should create your response handler in a looper thread or use SyncHttpClient instead." );
1306
1369
}
1307
-
1370
+
1308
1371
if (contentType != null ) {
1309
1372
if (uriRequest instanceof HttpEntityEnclosingRequestBase && ((HttpEntityEnclosingRequestBase ) uriRequest ).getEntity () != null && uriRequest .containsHeader (HEADER_CONTENT_TYPE )) {
1310
- Log .w (LOG_TAG , "Passed contentType will be ignored because HttpEntity sets content type" );
1373
+ log .w (LOG_TAG , "Passed contentType will be ignored because HttpEntity sets content type" );
1311
1374
} else {
1312
1375
uriRequest .setHeader (HEADER_CONTENT_TYPE , contentType );
1313
1376
}
@@ -1384,7 +1447,7 @@ public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url,
1384
1447
url = _uri .toASCIIString ();
1385
1448
} catch (Exception ex ) {
1386
1449
// Should not really happen, added just for sake of validity
1387
- Log .e (LOG_TAG , "getUrlWithQueryString encoding URL" , ex );
1450
+ log .e (LOG_TAG , "getUrlWithQueryString encoding URL" , ex );
1388
1451
}
1389
1452
}
1390
1453
@@ -1433,7 +1496,7 @@ public static void silentCloseInputStream(InputStream is) {
1433
1496
is .close ();
1434
1497
}
1435
1498
} catch (IOException e ) {
1436
- Log .w (LOG_TAG , "Cannot close input stream" , e );
1499
+ log .w (LOG_TAG , "Cannot close input stream" , e );
1437
1500
}
1438
1501
}
1439
1502
@@ -1448,7 +1511,7 @@ public static void silentCloseOutputStream(OutputStream os) {
1448
1511
os .close ();
1449
1512
}
1450
1513
} catch (IOException e ) {
1451
- Log .w (LOG_TAG , "Cannot close output stream" , e );
1514
+ log .w (LOG_TAG , "Cannot close output stream" , e );
1452
1515
}
1453
1516
}
1454
1517
@@ -1521,7 +1584,7 @@ public static void endEntityViaReflection(HttpEntity entity) {
1521
1584
}
1522
1585
}
1523
1586
} catch (Throwable t ) {
1524
- Log .e (LOG_TAG , "wrappedEntity consume" , t );
1587
+ log .e (LOG_TAG , "wrappedEntity consume" , t );
1525
1588
}
1526
1589
}
1527
1590
}
0 commit comments