Emit start & end events for queries being run.
Merge pull request #335 from wbyoung/debug-flag

Allow debug flag to be a function.