about summary refs log tree commit diff stats
path: root/003trace.cc
diff options
context:
space:
mode:
Diffstat (limited to '003trace.cc')
-rw-r--r--003trace.cc36
1 files changed, 29 insertions, 7 deletions
diff --git a/003trace.cc b/003trace.cc
index dd60ce42..af707354 100644
--- a/003trace.cc
+++ b/003trace.cc
@@ -109,16 +109,10 @@ ofstream null_stream;  // never opened, so writes to it silently fail
 //: Some constants.
 :(before "struct trace_stream")  // include constants in all cleaved compilation units
 const int Max_depth = 9999;
-// Most important traces are printed to the screen by default
-const int Error_depth = 0;
-:(before "End Globals")
-int Hide_errors = false;  // if set, don't print errors to screen
 :(before "End trace_stream Constructor")
 curr_stream = NULL;
 curr_depth = Max_depth;
 collect_depth = Max_depth;
-:(before "End Reset")
-Hide_errors = false;
 
 :(before "struct trace_stream")
 struct trace_line {
@@ -170,7 +164,7 @@ void trace_stream::newline() {
     past_lines.push_back(trace_line(curr_contents, trim(curr_label), curr_depth));  // preserve indent in contents
     // maybe incrementally dump trace
     trace_line& t = past_lines.back();
-    if (!Hide_errors && curr_depth == Error_depth) {
+    if (should_incrementally_print_trace()) {
       cerr       << std::setw(4) << t.depth << ' ' << t.label << ": " << t.contents << '\n';
     }
     // End trace Commit
@@ -208,6 +202,22 @@ lease_tracer::~lease_tracer() {
 :(before "End Includes")
 #define raise  (!Trace_stream ? (scroll_to_bottom_and_close_console(),++Trace_errors,cerr) /*do print*/ : Trace_stream->stream(Error_depth, "error"))
 
+//: Print errors to the screen by default.
+:(before "struct trace_stream")  // include constants in all cleaved compilation units
+const int Error_depth = 0;
+:(before "End Globals")
+int Hide_errors = false;  // if set, don't print errors to screen
+:(before "End Reset")
+Hide_errors = false;
+:(code)
+bool trace_stream::should_incrementally_print_trace() {
+  if (!Hide_errors && curr_depth == Error_depth) return true;
+  // End Incremental Trace Print Conditions
+  return false;
+}
+:(before "End trace_stream Methods")
+bool should_incrementally_print_trace();
+
 :(before "End Globals")
 int Trace_errors = 0;  // used only when Trace_stream is NULL
 
@@ -448,6 +458,18 @@ string readable_contents(string label) {
   return output.str();
 }
 
+//: Print traces to the screen as they happen.
+//: Particularly useful when juggling multiple trace streams, like when
+//: debugging sandboxes.
+:(before "End Globals")
+bool Dump_trace = false;
+:(before "End Commandline Options(*arg)")
+else if (is_equal(*arg, "--dump")) {
+  Dump_trace = true;
+}
+:(before "End Incremental Trace Print Conditions")
+if (Dump_trace) return true;
+
 //: Miscellaneous helpers.
 
 :(code)