From c1461e75826c9d8488b644bd8de1503d29e7b938 Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Fri, 24 May 2013 13:51:52 +0200 Subject: [PATCH] Added a null stream to suppress logging. --- .../include/PolyVoxCore/Impl/ErrorHandling.h | 3 +++ .../PolyVoxCore/source/Impl/ErrorHandling.cpp | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index d40a561a..b5100b25 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -68,6 +68,9 @@ freely, subject to the following restrictions: namespace PolyVox { + /// Get a stream which will consume all input without outputting anything. + std::ostream* getNullStream(void); + std::ostream& logTrace(void); std::ostream& logDebug(void); std::ostream& logInfo(void); diff --git a/library/PolyVoxCore/source/Impl/ErrorHandling.cpp b/library/PolyVoxCore/source/Impl/ErrorHandling.cpp index cce96bef..a3c2dedc 100644 --- a/library/PolyVoxCore/source/Impl/ErrorHandling.cpp +++ b/library/PolyVoxCore/source/Impl/ErrorHandling.cpp @@ -25,10 +25,21 @@ freely, subject to the following restrictions: namespace PolyVox { + /** + * \return A pointer to the null stream. + */ + std::ostream* getNullStream(void) + { + // Passing zero to the stream constructor guarentees it will discard all input. See + // here http://stackoverflow.com/a/8244052 and here http://stackoverflow.com/a/6240980 + static std::ostream s_NullStream = std::ostream(0); + return &s_NullStream; + } + // Trace stream for logging std::ostream*& getTraceStreamInstance() { - static std::ostream* s_pTraceStream = &(std::cerr); + static std::ostream* s_pTraceStream = getNullStream(); return s_pTraceStream; } @@ -45,7 +56,7 @@ namespace PolyVox // Debug stream for logging std::ostream*& getDebugStreamInstance() { - static std::ostream* s_pDebugStream = &(std::cerr); + static std::ostream* s_pDebugStream = getNullStream(); return s_pDebugStream; } @@ -62,7 +73,7 @@ namespace PolyVox // Info stream for logging std::ostream*& getInfoStreamInstance() { - static std::ostream* s_pInfoStream = &(std::cerr); + static std::ostream* s_pInfoStream = &(std::cout); return s_pInfoStream; }