Fix query logging

- Handle plugin paths correctly
- Include MaKaC code in stacktrace
- Include mako templates in stacktrace