Output debug info only in debug mode
Added testcase for #837