diff options
Diffstat (limited to 'debug.cc')
-rw-r--r-- | debug.cc | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -2,14 +2,26 @@ #ifdef DEBUG_ENABLED +#include <fstream> +#include <cstdlib> + namespace ledger { std::ostream * debug_stream = &std::cerr; bool free_debug_stream = false; -static class free_streams -{ - public: +static struct init_streams { + init_streams() { + // If debugging is enabled and DEBUG_FILE is set, all debugging + // output goes to that file. + if (const char * p = std::getenv("DEBUG_FILE")) { + debug_stream = new std::ofstream(p); + free_debug_stream = true; + } + } +} _debug_init; + +static struct free_streams { ~free_streams() { if (free_debug_stream && debug_stream) { delete debug_stream; |