How to see long LiveView errors truncated in the logs?

When working on LiveViews I often run into the problem that the assigns are so large that they cause the error message to get truncated, so you can’t see where the error happened, like in this example:

So I can see there was a (KeyError) key :selected_link not found in: #Phoenix.LiveView.Socket<[...long assigns]>, but the error message is truncated so I can’t see the location of the error (ie. path/to/index.ex, line 42).

Does anyone know a workaround for this, a way to see the full traceback?


The error logging docs are here - Logger — Logger v1.13.4

I haven’t played with the options, but truncate: :infinity may help. You may also need to set some “inspect options” that determine how the assigns is dropped into the error log. The options are documented here: Inspect.Opts — Elixir v1.13.4. Again, I haven’t played with it, but I would probably start with translator_inspect_opts: [limit: :infinity] in addition to the truncate option above.

Let us know how you go!


Infinities can be a bit dangerous in production, you don’t want to OOM your server trying to serialize out a log.

I actually agree that this is sort of a weird limitation of logs. The inspected value and the stack trace seem to get joined together in an opaque log string before the overall limit is applied, leading to the truncation of the stacktrace. I wonder if there is some sort of improvement to the logger that would be possible whereby the stacktrace could be considered a distinct thing from the log entry.


I tested it out, and as it turns out, it is sufficient to add

config :logger,
  truncate: :infinity

to your config/dev.exs (don’t put it in your main config file, you don’t want this set in production as @benwilson512 points out).

Apparently, Phoenix does also truncate the assigns at some point, but if you (like in my case) have a lot of text in your assigns, that truncation happens much later than the one at the logging level.

1 Like