Repository: wojtekmach/req
Pull request #370 (2024-06-07 09:25:29)

Default :retry_log_level to :warning
Closes https://github.com/wojtekmach/req/issues/369

jozuas: I've fixed the test :)
wojtekmach: Could you also double check docs examples? I believe we logs output in a couple of places.
jozuas: Nice point, done.

Patch:
diff --git a/lib/req.ex b/lib/req.ex
index f18b6dc..913487f 100644
--- a/lib/req.ex
+++ b/lib/req.ex
@@ -311,7 +311,7 @@ defmodule Req do
       and returns the delay, the number of milliseconds to sleep before making another attempt.
 
     * `:retry_log_level` - the log level to emit retry logs at. Can also be set to `false` to disable
-      logging these messages. Defaults to `:error`.
+      logging these messages. Defaults to `:warning`.
 
     * `:max_retries` - maximum number of retry attempts, defaults to `3` (for a total of `4`
       requests to the server, including the initial one.)
diff --git a/lib/req/steps.ex b/lib/req/steps.ex
index cc3d161..7998a7a 100644
--- a/lib/req/steps.ex
+++ b/lib/req/steps.ex
@@ -2206,7 +2206,7 @@ defmodule Req.Steps do
       and returns the delay, the number of milliseconds to sleep before making another attempt.
 
     * `:retry_log_level` - the log level to emit retry logs at. Can also be set to `false` to disable
-      logging these messages. Defaults to `:error`.
+      logging these messages. Defaults to `:warning`.
 
     * `:max_retries` - maximum number of retry attempts, defaults to `3` (for a total of `4`
       requests to the server, including the initial one.)
@@ -2216,16 +2216,16 @@ defmodule Req.Steps do
   With default options:
 
       iex> Req.get!("https://httpbin.org/status/500,200").status
-      # 19:02:08.463 [error] retry: got response with status 500, will retry in 2000ms, 2 attempts left
-      # 19:02:10.710 [error] retry: got response with status 500, will retry in 4000ms, 1 attempt left
+      # 19:02:08.463 [warning] retry: got response with status 500, will retry in 2000ms, 2 attempts left
+      # 19:02:10.710 [warning] retry: got response with status 500, will retry in 4000ms, 1 attempt left
       200
 
   Delay with jitter:
 
       iex> delay = fn n -> trunc(Integer.pow(2, n) * 1000 * (1 - 0.1 * :rand.uniform())) end
       iex> Req.get!("https://httpbin.org/status/500,200", retry_delay: delay).status
-      # 08:43:19.101 [error] retry: got response with status 500, will retry in 941ms, 2 attempts left
-      # 08:43:22.958 [error] retry: got response with status 500, will retry in 1877s, 1 attempt left
+      # 08:43:19.101 [warning] retry: got response with status 500, will retry in 941ms, 2 attempts left
+      # 08:43:22.958 [warning] retry: got response with status 500, will retry in 1877s, 1 attempt left
       200
 
   """
@@ -2324,7 +2324,7 @@ defmodule Req.Steps do
     retry_count = Req.Request.get_private(request, :req_retry_count, 0)
     {request, delay} = delay_getter.(request, response_or_exception, retry_count)
     max_retries = Req.Request.get_option(request, :max_retries, 3)
-    log_level = Req.Request.get_option(request, :retry_log_level, :error)
+    log_level = Req.Request.get_option(request, :retry_log_level, :warning)
 
     if retry_count < max_retries do
       log_retry(response_or_exception, retry_count, max_retries, delay, log_level)


Test patch:
diff --git a/lib/req/test.ex b/lib/req/test.ex
index f323fbd..ca3ae35 100644
--- a/lib/req/test.ex
+++ b/lib/req/test.ex
@@ -471,10 +471,10 @@ defmodule Req.Test do
       iex> Req.Test.expect(MyStub, 2, &Plug.Conn.send_resp(&1, 500, "internal server error"))
       iex> Req.Test.expect(MyStub, &Plug.Conn.send_resp(&1, 200, "ok"))
       iex> Req.get!(plug: {Req.Test, MyStub}).body
-      # 15:57:06.309 [error] retry: got exception, will retry in 1000ms, 3 attempts left
-      # 15:57:06.309 [error] ** (Req.TransportError) connection refused
-      # 15:57:07.310 [error] retry: got response with status 500, will retry in 2000ms, 2 attempts left
-      # 15:57:09.311 [error] retry: got response with status 500, will retry in 4000ms, 1 attempt left
+      # 15:57:06.309 [warning] retry: got exception, will retry in 1000ms, 3 attempts left
+      # 15:57:06.309 [warning] ** (Req.TransportError) connection refused
+      # 15:57:07.310 [warning] retry: got response with status 500, will retry in 2000ms, 2 attempts left
+      # 15:57:09.311 [warning] retry: got response with status 500, will retry in 4000ms, 1 attempt left
       "ok"
 
       iex> Req.request!(plug: {Req.Test, MyStub})
diff --git a/test/req/steps_test.exs b/test/req/steps_test.exs
index da3fe5d..e8b8aa1 100644
--- a/test/req/steps_test.exs
+++ b/test/req/steps_test.exs
@@ -1371,7 +1371,7 @@ defmodule Req.StepsTest do
 
       assert String.match?(
                log,
-               ~r/\[error\][[:blank:]]+retry: got response with status 500, will retry in 1ms, 3 attempts left/u
+               ~r/\[warning\][[:blank:]]+retry: got response with status 500, will retry in 1ms, 3 attempts left/u
              )
     end