Skip to content

Commit

Permalink
Refactor logs
Browse files Browse the repository at this point in the history
  • Loading branch information
FelonEkonom committed Jun 10, 2024
1 parent 82d8c04 commit 267f08f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
24 changes: 2 additions & 22 deletions lib/membrane/core/callback_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ defmodule Membrane.Core.CallbackHandler do
Error handling actions returned by callback #{inspect(state.module)}.#{callback}
""")

log_debug_orginal_error(actions, e, __STACKTRACE__)

reraise e, __STACKTRACE__
end

Expand All @@ -197,32 +195,14 @@ defmodule Membrane.Core.CallbackHandler do
rescue
e ->
Membrane.Logger.error("""
Error handling action #{inspect(action)} returned by callback #{inspect(state.module)}.#{callback}
Error handling action returned by callback #{inspect(state.module)}.#{callback}.
Action: #{inspect(action, pretty: true)}
""")

log_debug_orginal_error(action, e, __STACKTRACE__)

reraise e, __STACKTRACE__
end
end)

handler_module.handle_end_of_actions(state)
end

# We log it, because sometimes, for some reason, crashing process doesn't cause
# printing error logs on stderr, so this debug log allows us to get some info
# about what happened in case of process crash
defp log_debug_orginal_error(action_or_actions, error, stacktrace) do
action_or_actions =
if(is_list(action_or_actions), do: "actions ", else: "action ") <>
inspect(action_or_actions, limit: :infinity)

Membrane.Logger.debug("""
Error while handling #{action_or_actions}
Orginal error:
#{inspect(error, pretty: true, limit: :infinity)}
#{Exception.format_stacktrace(stacktrace)}
""")
end
end
2 changes: 2 additions & 0 deletions lib/membrane/core/macros.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule Membrane.Core.Macros do
@moduledoc false

# For some reason GenServer processes sometimes don't print logs about crash, so
# we add this macro, to ensure that error logs wil be always logged
defmacro log_on_error(do: code) do
quote do
try do
Expand Down

0 comments on commit 267f08f

Please sign in to comment.