4 ms·
I've been using Elixir for over 5 years and didn't know about .iex.exs. Nice!
by devoutsalsa 5y ago
I've been using Elixir for over 5 years and didn't know about .iex.exs. Nice!
- innocentoldguy 5y agoHere's a handy thing you can do with .iex.exs: Have you ever tried to debug something in iex, but database calls and other log messages keep stomping all over your prompt? You can stop them temporarily calling the function Logger.remove_backend(:console) You can start the log message again by typing Logger.add_backend(:console) That's a lot of typing though. Here's where .iex.exs comes in handy. You can include the following code in your .iex.exs file: defmodule Clog do def stop do Logger.remove_backend(:console) end def start do Logger.add_backend(:console) end end and then from within your iex session, type Clog.stop to stop the log message flow and Clog.start to start it up again. You can call your module whatever you'd like. I just called mine "Clog" because the log messages were always clogging up my console. I hope this helps.
- dnautics 5y agothis is even better: if function_exported?(Mix, :__info__, 1) and Mix.env() == :dev do Logger.configure_backend(:console, device: Process.group_leader()) end It makes logger work like IO; where if it spits it out it doesn't disrupt the prompt. Don't run it in prod, though.