diff options
author | kwolekr <kwolekr@minetest.net> | 2014-12-12 15:12:31 -0500 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2014-12-12 15:51:55 -0500 |
commit | 093b1b47d9c874b5d7d17e720f1f68f00d7c000e (patch) | |
tree | c3ff27134419b62e592bc73fcaa02974ed0092a1 /src | |
parent | 10e0cf8b2c27917a3fd45e73a5d835af4313db3b (diff) | |
download | minetest-093b1b47d9c874b5d7d17e720f1f68f00d7c000e.tar.gz minetest-093b1b47d9c874b5d7d17e720f1f68f00d7c000e.tar.bz2 minetest-093b1b47d9c874b5d7d17e720f1f68f00d7c000e.zip |
Log: Silence errorstream during unittests
Diffstat (limited to 'src')
-rw-r--r-- | src/log.cpp | 18 | ||||
-rw-r--r-- | src/log.h | 9 | ||||
-rw-r--r-- | src/test.cpp | 4 |
3 files changed, 30 insertions, 1 deletions
diff --git a/src/log.cpp b/src/log.cpp index ff2e16333..8ed1f7694 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -60,6 +60,21 @@ void log_remove_output(ILogOutput *out) } } +void log_set_lev_silence(enum LogMessageLevel lev, bool silence) +{ + log_threadnamemutex.Lock(); + + for (std::list<ILogOutput *>::iterator + it = log_outputs[lev].begin(); + it != log_outputs[lev].end(); + ++it) { + ILogOutput *out = *it; + out->silence = silence; + } + + log_threadnamemutex.Unlock(); +} + void log_register_thread(const std::string &name) { threadid_t id = get_current_thread_id(); @@ -107,6 +122,9 @@ void log_printline(enum LogMessageLevel lev, const std::string &text) for(std::list<ILogOutput*>::iterator i = log_outputs[lev].begin(); i != log_outputs[lev].end(); i++){ ILogOutput *out = *i; + if (out->silence) + continue; + out->printLog(os.str()); out->printLog(os.str(), lev); out->printLog(lev, text); @@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., /* Use this for logging everything. - + If you need to explicitly print something, use dstream or cout or cerr. */ @@ -39,18 +39,25 @@ enum LogMessageLevel { class ILogOutput { public: + ILogOutput() : + silence(false) + {} + /* line: Full line with timestamp, level and thread */ virtual void printLog(const std::string &line){}; /* line: Full line with timestamp, level and thread */ virtual void printLog(const std::string &line, enum LogMessageLevel lev){}; /* line: Only actual printed text */ virtual void printLog(enum LogMessageLevel lev, const std::string &line){}; + + bool silence; }; void log_add_output(ILogOutput *out, enum LogMessageLevel lev); void log_add_output_maxlev(ILogOutput *out, enum LogMessageLevel lev); void log_add_output_all_levs(ILogOutput *out); void log_remove_output(ILogOutput *out); +void log_set_lev_silence(enum LogMessageLevel lev, bool silence); void log_register_thread(const std::string &name); void log_deregister_thread(); diff --git a/src/test.cpp b/src/test.cpp index 072bda8ef..fa18989e5 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -2177,6 +2177,8 @@ void run_tests() IWritableNodeDefManager *ndef = createNodeDefManager(); define_some_nodes(idef, ndef); + log_set_lev_silence(LMT_ERROR, true); + infostream<<"run_tests() started"<<std::endl; TEST(TestUtilities); TEST(TestPath); @@ -2198,6 +2200,8 @@ void run_tests() dout_con<<"=== END RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl; } + log_set_lev_silence(LMT_ERROR, false); + delete idef; delete ndef; |