* prefixes for output to a file.
*/
unsigned int file_depth;
-
+
+ /**
+ * Flag for printing execution time.
+ */
+ bool print_utime;
public:
/**
* Standard constructor, since we
*/
void depth_file (unsigned int n);
+ /**
+ * Set time printing flag. If this flag
+ * is true, each output line will
+ * be prepended by the user time used
+ * by the running program so far.
+ */
+ void log_execution_time(bool flag);
+
/**
* Output a constant something through
* this stream.
* Declare this function as a friend.
*/
friend void endl (LogStream &);
+private:
+ /**
+ * Print head of line. This prints
+ * optional time information and
+ * the contents of the prefix stack.
+ */
+ void print_line_head();
};
prefixes.push(pre);
}
-
+inline
+void
+LogStream::log_execution_time(bool flag)
+{
+ print_utime = flag;
+}
// sorry for the weird following declaration spanning 5 lines, but
// doc++ gets confused if we be more compact :-(
// and a colon
if (was_endl)
{
- if (prefixes.size() <= std_depth)
- *std_out << prefixes.top() << ':';
-
- if (file && (prefixes.size() <= file_depth))
- *file << prefixes.top() << ':';
-
+ print_line_head();
was_endl = false;
};
#include <base/logstream.h>
#include <base/job_identifier.h>
-
+#include <sys/rusage.h>
LogStream deallog;
LogStream::LogStream()
: std_out(&cerr), file(0), was_endl(true),
- std_depth(10000), file_depth(10000)
+ std_depth(10000), file_depth(10000),
+ print_utime(false)
{
prefixes.push("DEAL:");
}
void LogStream::detach ()
{
file = 0;
-};
+}
-void LogStream::pop ()
+void
+LogStream::pop ()
{
prefixes.pop();
-};
+}
-void LogStream::depth_console(unsigned n)
+void
+LogStream::depth_console(unsigned n)
{
std_depth = n;
-};
+}
-void LogStream::depth_file(unsigned n)
+void
+LogStream::depth_file(unsigned n)
{
file_depth = n;
-};
+}
+
+
+void
+LogStream::print_line_head()
+{
+ if (prefixes.size() <= std_depth)
+ *std_out << prefixes.top() << ':';
+ if (file && (prefixes.size() <= file_depth))
+ *file << prefixes.top() << ':';
+}
LogStream&