diff options
author | John Hodge <tpg@mutabah.net> | 2018-05-19 10:15:20 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-05-19 10:15:20 +0800 |
commit | ae177706bf0b4b2ff05e9102d1403c73799756b0 (patch) | |
tree | 9e525e69d7a16a7ad77d56c2c8c6c5de598977bf /tools/standalone_miri/debug.cpp | |
parent | aada4f2fe9be2f9bfadb4ef6ba057f36b9860aa8 (diff) | |
download | mrust-ae177706bf0b4b2ff05e9102d1403c73799756b0.tar.gz |
Standalone MIRI - Better logging (can redirect to a file, leaving stdout for the program)
Diffstat (limited to 'tools/standalone_miri/debug.cpp')
-rw-r--r-- | tools/standalone_miri/debug.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/tools/standalone_miri/debug.cpp b/tools/standalone_miri/debug.cpp index 415bc5d5..f0476df7 100644 --- a/tools/standalone_miri/debug.cpp +++ b/tools/standalone_miri/debug.cpp @@ -1,6 +1,15 @@ +/* + * mrustc Standalone MIRI + * - by John Hodge (Mutabah) + * + * debug.cpp + * - Interpreter debug logging + */ #include "debug.hpp" +#include <fstream> unsigned DebugSink::s_indent = 0; +::std::unique_ptr<std::ofstream> DebugSink::s_out_file; DebugSink::DebugSink(::std::ostream& inner): m_inner(inner) @@ -10,39 +19,44 @@ DebugSink::~DebugSink() { m_inner << "\n"; } +bool DebugSink::set_output_file(const ::std::string& s) +{ + s_out_file.reset(new ::std::ofstream(s)); +} bool DebugSink::enabled(const char* fcn_name) { return true; } DebugSink DebugSink::get(const char* fcn_name, const char* file, unsigned line, DebugLevel lvl) { + auto& sink = s_out_file ? *s_out_file : ::std::cout; for(size_t i = s_indent; i--;) - ::std::cout << " "; + sink << " "; switch(lvl) { case DebugLevel::Trace: - ::std::cout << "Trace: " << file << ":" << line << ": "; + sink << "Trace: " << file << ":" << line << ": "; break; case DebugLevel::Debug: - ::std::cout << "DEBUG: " << fcn_name << ": "; + sink << "DEBUG: " << fcn_name << ": "; break; case DebugLevel::Notice: - ::std::cout << "NOTE: "; + sink << "NOTE: "; break; case DebugLevel::Warn: - ::std::cout << "WARN: "; + sink << "WARN: "; break; case DebugLevel::Error: - ::std::cout << "ERROR: "; + sink << "ERROR: "; break; case DebugLevel::Fatal: - ::std::cout << "FATAL: "; + sink << "FATAL: "; break; case DebugLevel::Bug: - ::std::cout << "BUG: " << file << ":" << line << ": "; + sink << "BUG: " << file << ":" << line << ": "; break; } - return DebugSink(::std::cout); + return DebugSink(sink); } void DebugSink::inc_indent() { @@ -51,4 +65,4 @@ void DebugSink::inc_indent() void DebugSink::dec_indent() { s_indent --; -}
\ No newline at end of file +} |