Skip to content

Commit 626d425

Browse files
committed
refactor: Upsert log stream only at initialization
1 parent 8052f26 commit 626d425

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/cadet/logger/cloudwatch_logger.ex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ defmodule Cadet.Logger.CloudWatchLogger do
2727
@impl true
2828
def init({__MODULE__, opts}) when is_list(opts) do
2929
config = configure_merge(read_env(), opts)
30-
{:ok, init(config, %__MODULE__{})}
30+
state = init(config, %__MODULE__{})
31+
ensure_log_stream_exists(state.log_group, state.log_stream)
32+
{:ok, state}
3133
end
3234

3335
@impl true
3436
def init({__MODULE__, name}) when is_atom(name) do
3537
config = read_env()
36-
{:ok, init(config, %__MODULE__{})}
38+
state = init(config, %__MODULE__{})
39+
ensure_log_stream_exists(state.log_group, state.log_stream)
40+
{:ok, state}
3741
end
3842

3943
@impl true
@@ -151,8 +155,7 @@ defmodule Cadet.Logger.CloudWatchLogger do
151155

152156
defp send_to_cloudwatch(log_stream, log_group, buffer) do
153157
# Ensure that the already have ExAws authentication configured
154-
with :ok <- check_exaws_config(),
155-
:ok <- ensure_log_stream_exists(log_group, log_stream) do
158+
with :ok <- check_exaws_config() do
156159
operation = build_log_operation(log_stream, log_group, buffer)
157160

158161
operation

0 commit comments

Comments
 (0)