Search⌘ K
AI Features

The run_erl and heartool

Understand how to use the run_erl tool for managing logs and input/output streams, and the heart tool for monitoring VM health and automatic restarts. This lesson helps you manage Elixir production deployments with enhanced logging, interactive debugging, and fault tolerance.

We'll cover the following...

Erlang is more than the standard library and virtual machine. As we might expect after thirty years of history, it ships with many tools for successfully running Erlang in production. Two of those tools are run_erl and heart.

Managing shared I/O

run_erl tool helps you manage the standard input and output of a program. The Unix tool redirects all output to log files. For those interested, there’s a similar Windows tool named start_erl.

The run_erl tool expects a pipe name, the log directory, and the command to execute.

Remember the log directory must be created before we invoke run_erl. Otherwise, it will silently fail.

We can run run_erl like this:

C++
mkdir ./log
run_erl ./loop ./log "elixir -e 'Enum.map Stream.interval(1000), &IO.puts/1'"

This command runs an Elixir script that prints a number to the standard output every second. Assuming we’ve created a log directory ...