summaryrefslogtreecommitdiff
path: root/debug.cc
diff options
context:
space:
mode:
Diffstat (limited to 'debug.cc')
-rw-r--r--debug.cc18
1 files changed, 15 insertions, 3 deletions
diff --git a/debug.cc b/debug.cc
index 428d5a4d..d8139ecc 100644
--- a/debug.cc
+++ b/debug.cc
@@ -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;