Skip to content

Commit

Permalink
Convert Logger to inline style
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed May 7, 2024
1 parent dcc7ad0 commit 47010ab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
36 changes: 14 additions & 22 deletions lib/modules/mnesia_assistant/error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ defmodule MnesiaAssistant.Error do

def error_description(error, identifier) when error in [{:atomic, :ok}, :ok] do
Logger.info(
"Identifier: #{inspect(identifier)}; The action concerned was completed successfully."
"Identifier: #{inspect(identifier)} ::: MnesiaMessage: The action concerned was completed successfully."
)

{:ok, :atomic}
end

def error_description(:starting, identifier) do
Logger.info(
"Identifier: #{inspect(identifier)}; The action concerned is being started successfully."
"Identifier: #{inspect(identifier)} ::: MnesiaMessage: The action concerned is being started successfully."
)

{:ok, :atomic}
Expand All @@ -89,11 +89,9 @@ defmodule MnesiaAssistant.Error do
def error_description({:aborted, {:already_exists, _module}} = error, identifier) do
converted = error_description(error)

Logger.warning("""
Identifier: #{inspect(identifier)}
MnesiaError: #{inspect(error)}
ConvertedError: #{inspect(converted)}
""")
Logger.warning(
"Identifier: #{inspect(identifier)} ::: MnesiaError: #{inspect(error)} ::: ConvertedError: #{inspect(converted)}"
)

err = if is_tuple(converted), do: to_string(elem(converted, 0)), else: converted
{:error, error, err}
Expand All @@ -102,11 +100,9 @@ defmodule MnesiaAssistant.Error do
def error_description({:error, {_, {:already_exists, _}}} = error, identifier) do
converted = error_description(error)

Logger.warning("""
Identifier: #{inspect(identifier)}
MnesiaError: #{inspect(error)}
ConvertedError: #{inspect(converted)}
""")
Logger.warning(
"Identifier: #{inspect(identifier)} ::: MnesiaError: #{inspect(error)} ::: ConvertedError: #{inspect(converted)}"
)

err = if is_tuple(converted), do: to_string(elem(converted, 0)), else: converted
{:error, error, err}
Expand All @@ -116,11 +112,9 @@ defmodule MnesiaAssistant.Error do
if elem(error_type, 0) in @error_types do
converted = error_description(error)

Logger.error("""
Identifier: #{inspect(identifier)}
MnesiaError: #{inspect(error)}
ConvertedError: #{inspect(converted)}
""")
Logger.error(
"Identifier: #{inspect(identifier)} ::: MnesiaError: #{inspect(error)} ::: ConvertedError: #{inspect(converted)}"
)

err = if is_tuple(converted), do: to_string(elem(converted, 0)), else: converted
{:error, error, err}
Expand All @@ -132,11 +126,9 @@ defmodule MnesiaAssistant.Error do
def error_description(error, identifier) do
converted = error_description(error)

Logger.error("""
Identifier: #{inspect(identifier)}
MnesiaError: #{inspect(error)}
ConvertedError: #{inspect(converted)}
""")
Logger.error(
"Identifier: #{inspect(identifier)} ::: MnesiaError: #{inspect(error)} ::: ConvertedError: #{inspect(converted)}"
)

{:error, error, converted}
end
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/mnesia_assistant/mnesia_assistant.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ defmodule MnesiaAssistant do

@doc false
def start(mode, dir, identifier) do
Logger.warning("Mnesia's initial valuation process has begun.")
Logger.warning(
"Identifier: #{inspect(identifier)} ::: MnesiaMessage: Mnesia's initial valuation process has begun."
)

stop() |> MError.error_description()
mnesia_dir = dir <> "/#{mode}"
File.mkdir_p(mnesia_dir) |> MError.error_description(identifier)
Expand Down
26 changes: 11 additions & 15 deletions lib/modules/mnesia_assistant/operation/table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ defmodule MnesiaAssistant.Table do
case wait_for_tables(tables, timeout) do
:ok ->
Logger.info(
"Identifier: #{inspect(identifier)}; The action concerned was completed successfully."
"Identifier: #{inspect(identifier)} ::: MnesiaMessage: The action concerned was completed successfully."
)

{:ok, :atomic}
Expand All @@ -286,22 +286,18 @@ defmodule MnesiaAssistant.Table do
{"The requested tables could not be loaded in the specified time #{timeout}.",
missing_tables}

Logger.error("""
Identifier: #{inspect(identifier)}
MnesiaError: #{inspect(error)}
ConvertedError: #{inspect(converted)}
""")
Logger.error(
"Identifier: #{inspect(identifier)} ::: MnesiaError: #{inspect(error)} ::: ConvertedError: #{inspect(converted)}"
)

{:error, error, elem(converted, 0)}

error ->
converted = MnesiaAssistant.Error.error_description(error)

Logger.error("""
Identifier: #{inspect(identifier)}
MnesiaError: #{inspect(error)}
ConvertedError: #{inspect(converted)}
""")
Logger.error(
"Identifier: #{inspect(identifier)} ::: MnesiaError: #{inspect(error)} ::: ConvertedError: #{inspect(converted)}"
)

err = if is_tuple(converted), do: to_string(elem(converted, 0)), else: converted
{:error, error, err}
Expand Down Expand Up @@ -858,7 +854,7 @@ defmodule MnesiaAssistant.Table do
re_wait_for_tables(true, [], number + 1, max_try, module, identifier, waiting_time)

error ->
Logger.error("Identifier: #{inspect(module)}; Source: #{inspect(error)}")
Logger.error("Identifier: #{inspect(module)} ::: Source: #{inspect(error)}")
{:error, :create_table, error, identifier}
end

Expand All @@ -868,7 +864,7 @@ defmodule MnesiaAssistant.Table do

error ->
Logger.error(
"Identifier: #{inspect(module)}; Tries to get the table again(count: #{number + 1}). Source: #{inspect(error)}"
"Identifier: #{inspect(module)} ::: MnesiaError: Tries to get the table again(count: #{number + 1}). ::: Source: #{inspect(error)}"
)

new_output =
Expand All @@ -886,15 +882,15 @@ defmodule MnesiaAssistant.Table do

defp re_wait_for_tables(false, output, number, _, module, identifier, _) do
Logger.error(
"Identifier: #{inspect(module)}; Tries to get the table again(count: #{number + 1}). Source: #{inspect(output)}"
"Identifier: #{inspect(module)} ::: MnesiaError: Tries to get the table again(count: #{number + 1}). ::: Source: #{inspect(output)}"
)

{:error, :create_table, output, identifier}
end

defp re_wait_for_tables(true, _output, number, max_try, module, identifier, waiting_time) do
Logger.warning(
"Identifier: #{inspect(module)}; Tries to get the table again(count: #{number})."
"Identifier: #{inspect(module)} ::: MnesiaError: Tries to get the table again(count: #{number})."
)

new_output =
Expand Down

0 comments on commit 47010ab

Please sign in to comment.