cool-RR / PySnooper

Never use print for debugging again
MIT License
16.39k stars 954 forks source link

Add log function #119

Closed alexmojaki closed 5 years ago

alexmojaki commented 5 years ago

I know this library is against print style debugging, but sometimes it has its uses. This helps when the usual pysnooper methods are not ideal. For example:

  1. To see a single full value, as in #104. This is more convenient than changing MAX_VARIABLE_LENGTH and doesn't globally make the output more verbose.
  2. To see just one value without all the other stuff from snoop. Even using with on a single line can print out a bunch of irrelevant variables. This can be used in places where there is no decorator or block.
  3. To see a value that doesn't have a local variable, without having to rearrange the code and invent a temporary variable. Like the libraries q and icecream, this lets the arguments pass through for minimal code disruption. It's also good for people who are tired and used to print debugging so they don't think of adding a local variable.
  4. To see a value just once, if evaluating its repr every line is terrible for performance or seeing every modification to its value would be disruptive.

The main advantage over print is that this is combined with the other output nicely, no matter the output method.

cool-RR commented 5 years ago

This is nice functionality, but I'm very hesitant to increase the scope of PySnooper. It's supposed to be a minimalistic little tool, and adding stuff might hurt that. Sorry. People who want to print their expressions can just print them, and people who want a powerful debugger can use an actual debugger.