phoenixframework / phoenix_live_reload

Provides live-reload functionality for Phoenix
MIT License
315 stars 90 forks source link

Add optional minimum log level to send to client #154

Open joshamb opened 6 months ago

joshamb commented 6 months ago

This is a new feature! Our logging is fairly extensive and I'm only really interested on seeing when things are breaking (ie a LiveView screen I've butchered) and not all the noise in-between in my web console.

The variable name could probably be better, but i've added a web_console_logger_min_log_level option for dev.exs where it compares the log level of the log (or defaults to the current behaviour, showing all logs)

I've also added a test, its essentially sends logs for web console only when enabled test but slightly repurposed, it might need some improving. Im a total test rookie so apologies in advanced if this came across as lazy.

chrismccord commented 6 months ago

Let’s filter on the client instead via the enableServerLogs method. This way you can control what you get in real time from your app js or on the browser console itself. Then there is no config required

joshamb commented 6 months ago

I think I instinctively did it on the server to reduce unnecessary logs being sent down the channel, but I agree its probably best having it on the client to be able to change it in real-time.

The only think I dislike about this is that I now have a elixirLogLevels variable, which is effectively a copy and paste of the elixir/erlang log levels.

I could send down the log levels on the socket 'join', but it would still be a hardcoded list, as in elixir 1.16 levels() is returned in an incorrect order. It could be ordered by comparing all the levels with each other - but seems a bit excessive?

And looking back to pre 1.16, there is no such levels() function.

Heres how it would look (untested): https://github.com/joshamb/phoenix_live_reload/commit/fc61192c6d95ca8a7f02d4864356fb232f3ebb18#diff-74e0d6ac64bd822b5fddb3c26cfbfa24e9b3ca6dc6b99ba041d933bf90bb2de6

chrismccord commented 6 months ago

The hardcoded list is fine. We can include the min log level on the enableServerLogs() and ditch the extra public interface, iereloader.enableServerLogs("error")

joshamb commented 6 months ago

Sorry you did mention that, done