When using Elixir you will spent a lot of time in IEx
(the Elixir’s interactive shell), so it makes sense to try improving the experience.
Shell history
One element which is quite important is to enable shell history
, as specified in the IEx doc, it can be done in multiple ways:
With CLI
arguments (on-demand)
iex --erl "-kernel shell_history enabled"
With environment variables
set on shell startup (always enabled)
On Unix-like (Linux, MacOS) add this line to your shell’s config file:
# for bash/zsh shell
export ERL_AFLAGS="-kernel shell_history enabled"
# for fish shell
set -gx ERL_AFLAGS "-kernel shell_history enabled"
Note that those will be used directly by Erlang.
Elixir binaries (elixir
, elixirc
, iex
, mix
) also read this informatiom from ELIXIR_ERL_OPTIONS
. So, if you want to enable the shell history
only when using Elixir, you can use instead:
# for bash/zsh shell
export ELIXIR_ERL_OPTIONS="-kernel shell_history enabled"
# for fish shell
set -gx ELIXIR_ERL_OPTIONS "-kernel shell_history enabled"
Change Logger
level at runtime
When deploying your Elixir application it’s common to decrease the amount of log it generated by default.
For example (Phoenix)(https://phoenixframework.org/) production config, the default level is set to :info
via:
config :logger, level: :info
But when confronted with an issue which doesn’t show up in the logs, it can be useful to temporarily change the level
to something like :debug
on the live application.
If your using mix release to generate you application, you can use the generated shell script in bin/RELEASE_NAME
(where RELEASE_NAME
is the name of your application) to start a new remote shell
(it will be an IEx
session) which is executed inside your running application:
Start a new remote shell
bin/my_app remote
Change the runtime Logger level
Logger.configure(level: :debug)
Logger.configure_backend(:console, [level: :debug])
You will then see debug messages
in your logs. Once you’re done, don’t forget to revert the changes.
Logger.configure(level: :info)
Logger.configure_backend(:console, [level: :info])