IO.inspect without newline characters

I’ve deployed a phx app to aws ECS and I use IO.inspect while still in the early stages of “productionizm”. The issue is ECS parses the output from it line by line so if what I am logging has 5 lines of output it’s treated as 5 different log lines in cloudwatch. Is there a way to disable this behavior in IO.inspect or something else I can do to have normal logs?

IO.inspect isn’t a tool for logging. It just happens to get captured if you pull logs from stdout. If you want logs then you want to use Logger api and possibly combine it with #{inspect data}.

Got it, again, I didn’t plan to use it for logging or long term just for debugging purposes right now since it’s very convenient but I didn’t know about #{inspect data}, thank you!

there is also IO.puts for quick and dirty debugging purposes

IO.inspect is roughly implemented like this:

def io_inspect(value, options) do
  IO.puts(inspect(value, options))
  value
end

(of course ignoring options such as label and al’)

Now the Logger will also output newlines, so if you want a strict 1log=1line you may need to use a JSON logger. This one has support for ECS.

1 Like