Clouseau - A `IO.inspect` enhancement

When I write elixir code I find my self sprinkling IO.inspect calls all over the place. More than two calls and I loose track of where the call came from. I have to comb the code to find the calls so I can remove the IO.inspect call.

The label: option helps if I remember to add "#{__MODULE__}: My label"but still the key presses are a bit awkward to use all the time. Also usually I remember using that format when I seek to remove it.

This is why I wrote Clouseau. It is just a wrapper around IO.inspect. It exports two macros Cl.inspect that can be used like IO.inspect. The macros can display the module, the line and the file where the call has happened.
Optionally it can display a border under the inspected term to distinguish it from the rest of the output. The downside is, since they are macros, the Cl module has to be required in order to use the macros.

All display options are configurable in the call, by using switches, or from the config.exs file

Finally, for those who use credo there are two credo checks that warn against using the macros or requiring the Cl. Just like the checks for IO.inspect

I would love to hear comments and suggestions for this project.

12 Likes

Such a funny name for a lib. I guess You must be a pink panther fan, like me :slight_smile:

3 Likes

I wanted a funny name because it was meant to be a quick hack. Then it evolved with a bit more features but I liked the name and decided to keep it. :smiley:

2 Likes

Version 0.4.0 is up in hex.pm. It adds color support with default and configurable colors. Also it uses iolists for the template.

I am all ears for suggestions or any other comments you may have.

3 Likes

Minor comment - similar functionality is available via good ‘ol Logger.debug. Just add $metadata in your logger and set :metadata option to [:file, :module, :function, :line].

4 Likes

Thanks. To be honest I didn’t study the Logger module up until now that you mentioned it. Had I done so I would probably base the package around Logger instead of IO.inspect. At least this way one maybe could do require Logger instead of require Cl in their code which is more useful.

From what I gathered from my reading upon Logger this morning, still it is not trivial to get the same output from Logger like the one Clouseau provides. One has to configure appropriately the Logger in config.ex and also call logger like

Logger.debug("#{inspect(users, [pretty: true, syntax_colors: [number: :yellow]])}")

or create a custom formatter module. At least that is my understanding so far.

Maybe in the future I will seek to redesign the functionality around Logger since it seems to provide for free many things that Clouseau creates from scratch. Thank you for pointing that out.

3 Likes