snooper v0.1.0 Snooper View Source
Easily debug, inspect, and log a function's behavior on a line-by-line basis.
Use like so:
defmodule SnooperDocTest do
import Snooper
snoop def a_long_function(my_other_string) do
some_string = "Hello World"
some_other_string = "Hello Joe"
string_stream = Stream.cycle([some_string, some_other_string, my_other_string])
a_long_string = Enum.join(Enum.take(string_stream, 5), ", ")
String.replace(a_long_string, "World", "Erlang")
end
end
Gives output like:
iex> SnooperDocTest.a_long_function("Hello Elixir")
[snoop:76849672:323] Entered Elixir.SnooperDocTest.a_long_function(my_other_string), arg bindings: [my_other_string: "Hello Elixir"]
[snoop:76849672:323] Line 7: some_string = "Hello World"
[snoop:76849672:323] Line 7 evaluated to: "Hello World", new bindings: [some_string: "Hello World"]
[snoop:76849672:323] Line 8: some_other_string = "Hello Joe"
[snoop:76849672:323] Line 8 evaluated to: "Hello Joe", new bindings: [some_other_string: "Hello Joe"]
[snoop:76849672:323] Line 9: string_stream = Stream.cycle([some_string, some_other_string, my_other_string])
[snoop:76849672:323] Line 9 evaluated to: #Function<65.126435914/2 in Stream.unfold/2>, new bindings: [string_stream: #Function<65.126435914/2 in Stream.unfold/2>]
[snoop:76849672:323] Line 10: a_long_string = Enum.join(Enum.take(string_stream, 5), ", ")
[snoop:76849672:323] Line 10 evaluated to: "Hello World, Hello Joe, Hello Elixir, Hello World, Hello Joe", new bindings: [a_long_string: "Hello World, Hello Joe, Hello Elixir, Hello World, Hello Joe"]
[snoop:76849672:323] Line 11: String.replace(a_long_string, "World", "Erlang")
[snoop:76849672:323] Returning: "Hello Erlang, Hello Joe, Hello Elixir, Hello Erlang, Hello Joe"
"Hello Erlang, Hello Joe, Hello Elixir, Hello Erlang, Hello Joe"
The snoop:a:b tags represent the function being snooped (a), and a given execution of it (b). a will always be the same for a given snooped function, but b will always be unique.
Link to this section Summary
Link to this section Functions
Link to this macro