mikl

mikl

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?

Marked As Solved

mikl

mikl

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.

Also Liked

mindok

mindok

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!

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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.

tomconroy

tomconroy

Important note: This isn’t something to add to the config :logger, :console, … line, it should be a new line to itself

Where Next?

Popular in Questions Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement