diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h index eb27c6a2..e97e27af 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Config.h @@ -25,7 +25,6 @@ freely, subject to the following restrictions: #define __PolyVox_Config_H__ #define POLYVOX_ASSERTS_ENABLED -#define POLYVOX_LOGGING_ENABLED #define POLYVOX_THROW_ENABLED #endif diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h index 3e80d6b7..8df554a3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/ErrorHandling.h @@ -29,6 +29,7 @@ freely, subject to the following restrictions: #include // For std::exit #include // For std::cerr #include +#include #include // Exception constuctors take strings. #if defined(_MSC_VER) @@ -82,8 +83,15 @@ namespace PolyVox LogHandler getLogHandler(); void setLogHandler(LogHandler newHandler); - //The actual logging function + // The actual logging function void log(const std::string& message, LogLevel logLevel); + + // Some handy wrappers + void logDebug (const std::string& message); + void logInfo (const std::string& message); + void logWarning(const std::string& message); + void logError (const std::string& message); + void logFatal (const std::string& message); } /* @@ -106,12 +114,14 @@ namespace PolyVox { \ if (!(condition)) \ { \ - std::cerr << std::endl << std::endl; \ - std::cerr << " PolyVox Assertion Failed!" << std::endl; \ - std::cerr << " =========================" << std::endl; \ - std::cerr << " Condition: " << #condition << std::endl; \ - std::cerr << " Message: " << (message) << std::endl; \ - std::cerr << " Location: " << "Line " << __LINE__ << " of " << __FILE__ << std::endl << std::endl; \ + std::stringstream ss; \ + ss << std::endl << std::endl; \ + ss << " PolyVox Assertion Failed!" << std::endl; \ + ss << " =========================" << std::endl; \ + ss << " Condition: " << #condition << std::endl; \ + ss << " Message: " << (message) << std::endl; \ + ss << " Location: " << "Line " << __LINE__ << " of " << __FILE__ << std::endl << std::endl; \ + logFatal(ss.str()); \ POLYVOX_HALT(); \ } \ } while(0) \ diff --git a/library/PolyVoxCore/source/Impl/ErrorHandling.cpp b/library/PolyVoxCore/source/Impl/ErrorHandling.cpp index 06472c1e..7c1cde82 100644 --- a/library/PolyVoxCore/source/Impl/ErrorHandling.cpp +++ b/library/PolyVoxCore/source/Impl/ErrorHandling.cpp @@ -82,29 +82,57 @@ namespace PolyVox } } + // Some handy wrappers + void logDebug(const std::string& message) + { + log(message, LogLevels::Debug ); + } + + void logInfo(const std::string& message) + { + log(message, LogLevels::Info); + } + + void logWarning(const std::string& message) + { + log(message, LogLevels::Warning); + } + + void logError(const std::string& message) + { + log(message, LogLevels::Error); + } + + void logFatal(const std::string& message) + { + log(message, LogLevels::Fatal); + } + #ifndef POLYVOX_THROW_ENABLED void defaultThrowHandler(std::exception& e, const char* file, int line) { - std::cerr << std::endl << std::endl; \ - std::cerr << " PolyVox exception thrown!" << std::endl; \ - std::cerr << " =========================" << std::endl; \ - std::cerr << " PolyVox has tried to throw an exception but it was built without support" << std::endl; \ - std::cerr << " for exceptions. In this scenario PolyVox will call a 'throw handler'" << std::endl; \ - std::cerr << " and this message is being printed by the default throw handler." << std::endl << std::endl; \ + std::stringstream ss; \ + ss << std::endl << std::endl; \ + ss << " PolyVox exception thrown!" << std::endl; \ + ss << " =========================" << std::endl; \ + ss << " PolyVox has tried to throw an exception but it was built without support" << std::endl; \ + ss << " for exceptions. In this scenario PolyVox will call a 'throw handler'" << std::endl; \ + ss << " and this message is being printed by the default throw handler." << std::endl << std::endl; \ - std::cerr << " If you don't want to enable exceptions then you should try to determine why" << std::endl; \ - std::cerr << " this exception was thrown and make sure it doesn't happen again. If it was" << std::endl; \ - std::cerr << " due to something like an invalid argument to a function then you should be" << std::endl; \ - std::cerr << " able to fix it quite easily by validating parameters as appropriate. More" << std::endl; \ - std::cerr << " complex exception scenarios (out of memory, etc) might be harder to fix and" << std::endl; \ - std::cerr << " you should replace this default handler with something which is more" << std::endl; \ - std::cerr << " meaningful to your users." << std::endl << std::endl; \ + ss << " If you don't want to enable exceptions then you should try to determine why" << std::endl; \ + ss << " this exception was thrown and make sure it doesn't happen again. If it was" << std::endl; \ + ss << " due to something like an invalid argument to a function then you should be" << std::endl; \ + ss << " able to fix it quite easily by validating parameters as appropriate. More" << std::endl; \ + ss << " complex exception scenarios (out of memory, etc) might be harder to fix and" << std::endl; \ + ss << " you should replace this default handler with something which is more" << std::endl; \ + ss << " meaningful to your users." << std::endl << std::endl; \ - std::cerr << " Exception details" << std::endl; \ - std::cerr << " -----------------" << std::endl; \ - std::cerr << " Line: " << line << std::endl; \ - std::cerr << " File: " << file << std::endl; \ - std::cerr << " Message: " << e.what() << std::endl << std::endl; \ + ss << " Exception details" << std::endl; \ + ss << " -----------------" << std::endl; \ + ss << " Line: " << line << std::endl; \ + ss << " File: " << file << std::endl; \ + ss << " Message: " << e.what() << std::endl << std::endl; \ + logFatal(ss.str()); \ POLYVOX_HALT(); \ }