9
9
10
10
-module (rabbit_peer_discovery_httpc ).
11
11
12
+ -include_lib (" kernel/include/logger.hrl" ).
12
13
-include (" include/rabbit_peer_discovery.hrl" ).
13
14
14
15
% %
@@ -138,10 +139,10 @@ get(Scheme, Host, Port, Path, Args) ->
138
139
% %
139
140
get (Scheme , Host , Port , Path , Args , Headers , HttpOpts ) ->
140
141
URL = build_uri (Scheme , Host , Port , Path , Args ),
141
- rabbit_log : debug (" GET ~s " , [URL ]),
142
+ ? LOG_DEBUG (" GET ~s " , [URL ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
142
143
HttpOpts1 = ensure_timeout (HttpOpts ),
143
144
Response = httpc :request (get , {URL , Headers }, HttpOpts1 , []),
144
- rabbit_log : debug (" Response: ~p " , [Response ]),
145
+ ? LOG_DEBUG (" Response: ~p " , [Response ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
145
146
parse_response (Response ).
146
147
147
148
@@ -176,10 +177,10 @@ post(Scheme, Host, Port, Path, Args, Body) ->
176
177
% %
177
178
post (Scheme , Host , Port , Path , Args , Headers , HttpOpts , Body ) ->
178
179
URL = build_uri (Scheme , Host , Port , Path , Args ),
179
- rabbit_log : debug (" POST ~s [~p ]" , [URL , Body ]),
180
+ ? LOG_DEBUG (" POST ~s [~p ]" , [URL , Body ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
180
181
HttpOpts1 = ensure_timeout (HttpOpts ),
181
182
Response = httpc :request (post , {URL , Headers , ? CONTENT_JSON , Body }, HttpOpts1 , []),
182
- rabbit_log : debug (" Response: [~p ]" , [Response ]),
183
+ ? LOG_DEBUG (" Response: [~p ]" , [Response ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
183
184
parse_response (Response ).
184
185
185
186
@@ -205,10 +206,10 @@ post(Scheme, Host, Port, Path, Args, Headers, HttpOpts, Body) ->
205
206
Body :: string () | binary () | tuple ().
206
207
put (Scheme , Host , Port , Path , Args , Body ) ->
207
208
URL = build_uri (Scheme , Host , Port , Path , Args ),
208
- rabbit_log : debug (" PUT ~s [~p ]" , [URL , Body ]),
209
+ ? LOG_DEBUG (" PUT ~s [~p ]" , [URL , Body ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
209
210
HttpOpts = ensure_timeout (),
210
211
Response = httpc :request (put , {URL , [], ? CONTENT_URLENCODED , Body }, HttpOpts , []),
211
- rabbit_log : debug (" Response: [~p ]" , [Response ]),
212
+ ? LOG_DEBUG (" Response: [~p ]" , [Response ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
212
213
parse_response (Response ).
213
214
214
215
@@ -234,10 +235,10 @@ put(Scheme, Host, Port, Path, Args, Body) ->
234
235
Body :: string () | binary () | tuple ().
235
236
put (Scheme , Host , Port , Path , Args , Headers , Body ) ->
236
237
URL = build_uri (Scheme , Host , Port , Path , Args ),
237
- rabbit_log : debug (" PUT ~s [~p ] [~p ]" , [URL , Headers , Body ]),
238
+ ? LOG_DEBUG (" PUT ~s [~p ] [~p ]" , [URL , Headers , Body ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
238
239
HttpOpts = ensure_timeout (),
239
240
Response = httpc :request (put , {URL , Headers , ? CONTENT_URLENCODED , Body }, HttpOpts , []),
240
- rabbit_log : debug (" Response: [~p ]" , [Response ]),
241
+ ? LOG_DEBUG (" Response: [~p ]" , [Response ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
241
242
parse_response (Response ).
242
243
243
244
@@ -258,10 +259,10 @@ delete(Scheme, Host, Port, PathSegments, Args, Body) when is_list(PathSegments)
258
259
delete (Scheme , Host , Port , Path , Args , Body );
259
260
delete (Scheme , Host , Port , Path , Args , Body ) ->
260
261
URL = build_uri (Scheme , Host , Port , Path , Args ),
261
- rabbit_log : debug (" DELETE ~s [~p ]" , [URL , Body ]),
262
+ ? LOG_DEBUG (" DELETE ~s [~p ]" , [URL , Body ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
262
263
HttpOpts = ensure_timeout (),
263
264
Response = httpc :request (delete , {URL , [], ? CONTENT_URLENCODED , Body }, HttpOpts , []),
264
- rabbit_log : debug (" Response: [~p ]" , [Response ]),
265
+ ? LOG_DEBUG (" Response: [~p ]" , [Response ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
265
266
parse_response (Response ).
266
267
267
268
@@ -275,14 +276,18 @@ maybe_configure_proxy() ->
275
276
Map = ? CONFIG_MODULE :config_map (? CONFIG_KEY ),
276
277
case map_size (Map ) of
277
278
0 ->
278
- rabbit_log :debug (" HTTP client proxy is not configured" ),
279
+ ? LOG_DEBUG (
280
+ " HTTP client proxy is not configured" ,
281
+ #{domain => ? RMQLOG_DOMAIN_PEER_DIS }),
279
282
ok ;
280
283
_ ->
281
284
HttpProxy = ? CONFIG_MODULE :get (http_proxy , ? CONFIG_MAPPING , Map ),
282
285
HttpsProxy = ? CONFIG_MODULE :get (https_proxy , ? CONFIG_MAPPING , Map ),
283
286
ProxyExclusions = ? CONFIG_MODULE :get (proxy_exclusions , ? CONFIG_MAPPING , Map ),
284
- rabbit_log :debug (" Configured HTTP proxy: ~p , HTTPS proxy: ~p , exclusions: ~p " ,
285
- [HttpProxy , HttpsProxy , ProxyExclusions ]),
287
+ ? LOG_DEBUG (
288
+ " Configured HTTP proxy: ~p , HTTPS proxy: ~p , exclusions: ~p " ,
289
+ [HttpProxy , HttpsProxy , ProxyExclusions ],
290
+ #{domain => ? RMQLOG_DOMAIN_PEER_DIS }),
286
291
maybe_set_proxy (proxy , HttpProxy , ProxyExclusions ),
287
292
maybe_set_proxy (https_proxy , HttpsProxy , ProxyExclusions ),
288
293
ok
@@ -315,9 +320,10 @@ maybe_set_proxy(Option, ProxyUrl, ProxyExclusions) ->
315
320
UriMap ->
316
321
Host = maps :get (host , UriMap ),
317
322
Port = maps :get (port , UriMap , 80 ),
318
- rabbit_log : debug (
323
+ ? LOG_DEBUG (
319
324
" Configuring HTTP client's ~s setting: ~p , exclusions: ~p " ,
320
- [Option , {Host , Port }, ProxyExclusions ]),
325
+ [Option , {Host , Port }, ProxyExclusions ],
326
+ #{domain => ? RMQLOG_DOMAIN_PEER_DIS }),
321
327
httpc :set_option (Option , {{Host , Port }, ProxyExclusions })
322
328
end .
323
329
@@ -360,9 +366,11 @@ decode_body(?CONTENT_JSON, Body) ->
360
366
{ok , Value } ->
361
367
Value ;
362
368
{error , Err } ->
363
- rabbit_log :error (" HTTP client could not decode a JSON payload "
364
- " (JSON parser returned an error): ~p .~n " ,
365
- [Err ]),
369
+ ? LOG_ERROR (
370
+ " HTTP client could not decode a JSON payload "
371
+ " (JSON parser returned an error): ~p .~n " ,
372
+ [Err ],
373
+ #{domain => ? RMQLOG_DOMAIN_PEER_DIS }),
366
374
[]
367
375
end .
368
376
@@ -375,14 +383,14 @@ decode_body(?CONTENT_JSON, Body) ->
375
383
-spec parse_response ({ok , integer (), string ()} | {error , any ()}) -> {ok , string ()} | {error , any ()}.
376
384
377
385
parse_response ({error , Reason }) ->
378
- rabbit_log : debug (" HTTP error ~p " , [Reason ]),
386
+ ? LOG_DEBUG (" HTTP error ~p " , [Reason ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
379
387
{error , lists :flatten (io_lib :format (" ~p " , [Reason ]))};
380
388
381
389
parse_response ({ok , 200 , Body }) -> {ok , decode_body (? CONTENT_JSON , Body )};
382
390
parse_response ({ok , 201 , Body }) -> {ok , decode_body (? CONTENT_JSON , Body )};
383
391
parse_response ({ok , 204 , _ }) -> {ok , []};
384
392
parse_response ({ok , Code , Body }) ->
385
- rabbit_log : debug (" HTTP Response (~p ) ~s " , [Code , Body ]),
393
+ ? LOG_DEBUG (" HTTP Response (~p ) ~s " , [Code , Body ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
386
394
{error , integer_to_list (Code )};
387
395
388
396
parse_response ({ok , {{_ ,200 ,_ }, Headers , Body }}) ->
@@ -391,7 +399,7 @@ parse_response({ok,{{_,201,_}, Headers, Body}}) ->
391
399
{ok , decode_body (proplists :get_value (" content-type" , Headers , ? CONTENT_JSON ), Body )};
392
400
parse_response ({ok ,{{_ ,204 ,_ }, _ , _ }}) -> {ok , []};
393
401
parse_response ({ok ,{{_Vsn ,Code ,_Reason },_ ,Body }}) ->
394
- rabbit_log : debug (" HTTP Response (~p ) ~s " , [Code , Body ]),
402
+ ? LOG_DEBUG (" HTTP Response (~p ) ~s " , [Code , Body ], #{ domain => ? RMQLOG_DOMAIN_PEER_DIS } ),
395
403
{error , integer_to_list (Code )}.
396
404
397
405
% % @private
0 commit comments