Skip to content

Commit

Permalink
Merge pull request #61 from aws-beam/jv-log-retries-as-info
Browse files Browse the repository at this point in the history
Log retries as info
  • Loading branch information
onno-vos-dev authored Dec 22, 2023
2 parents 03ea506 + 1158919 commit 527acc0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,6 @@ Different credential providers may have other settings which you can use to
change their behaviors. See the documentation for each provider for more
details.

Error Logging
-------------

If you prefer to not log errors as they happen (the default behavior), but accumulate
them for later, you can set erlang environment variable `log_errors_immediately` to
`false` as in this example:

```erlang
{aws_credentials, [{log_errors_immediately, false}]
},
```

License and copyright
---------------------
This project is licensed under the terms of the Apache 2 license. It is a
Expand Down
8 changes: 0 additions & 8 deletions src/aws_credentials.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
, make_map/3
, make_map/4
, make_map/5
, log_error/3
]).

-record(state, { credentials = undefined :: map()
Expand Down Expand Up @@ -168,13 +167,6 @@ format_status(_, [_PDict, State]) ->
%% Internal functions
%%====================================================================

-spec log_error(String :: unicode:chardata(), Args :: [term()], logger:metadata()) -> ok.
log_error(String, Args, Metadata) ->
case application:get_env(aws_credentials, log_errors_immediately, true) of
true -> ?LOG_ERROR(String, Args, Metadata);
false -> ?LOG_INFO(String, Args, Metadata)
end.

-spec fetch_credentials(aws_credentials_provider:options()) ->
{ok, credentials() | 'undefined', reference() | 'undefined'}.
fetch_credentials(Options) ->
Expand Down
8 changes: 4 additions & 4 deletions src/aws_credentials_httpc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ request(Method, URL, RequestHeaders, Tries, Remaining, Errs) ->

Error ->
NewRemaining = Remaining - 1,
String = "Error fetching URL (attempts left: ~p of ~p) ~p: ~p.",
Args = [NewRemaining, Tries, URL, Error],
Metadata = #{domain => [aws_credentials]},
aws_credentials:log_error(String, Args, Metadata),
?LOG_INFO("Error fetching URL (attempts left: "
"~p of ~p) ~p: ~p.",
[NewRemaining, Tries, URL, Error],
#{domain => [aws_credentials]}),
timer:sleep((Tries - NewRemaining) * ?DELAY),
request(Method, URL, RequestHeaders, Tries, NewRemaining, [ Error | Errs ])
end.
Expand Down

0 comments on commit 527acc0

Please sign in to comment.