16 #include "imstkSpinLock.h" 19 #include "g3log/loglevels.hpp" 33 #define IMSTK_CURRENT_FUNCTION __func__ 34 #elif defined(__FUNCSIG__) 35 #define IMSTK_CURRENT_FUNCTION __FUNCSIG__ 36 #elif defined(__PRETTY_FUNCTION__) 37 #define IMSTK_CURRENT_FUNCTION __PRETTY_FUNCTION__ 38 #elif defined(__FUNCTION__) 39 #define IMSTK_CURRENT_FUNCTION __FUNCTION__ 41 #define IMSTK_CURRENT_FUNCTION "???" 44 #define IMSTK_MAKE_STRING(x) #x 64 virtual bool writeMessage(
const std::string& message) = 0;
108 bool writeMessage(
const std::string& message)
override;
111 std::ostream& m_stream;
124 bool writeMessage(
const std::string& message)
override;
126 bool hasMessages()
const;
128 std::string popLastMessage();
131 std::ofstream m_outFile;
132 std::shared_ptr<StreamOutput> m_fileOutput;
133 std::deque<std::string> m_messages;
142 LoggerSynchronous(std::shared_ptr<LogOutput> output) : m_threshold(DEBUG.value), m_name(
"imstk"), m_output(output) { }
144 static std::shared_ptr<LoggerSynchronous> instance()
146 static std::shared_ptr<LoggerSynchronous> defaultLogger = std::make_shared<LoggerSynchronous>(
147 std::make_shared<CacheOutput>());
148 return defaultLogger;
162 return m_output->writeMessage(message);
192 return std::dynamic_pointer_cast<
CacheOutput>(m_output);
202 std::string getName()
210 std::shared_ptr<LogOutput> m_output;
238 LogMessageBase& operator <<(std::ios_base& (*manipulator)(std::ios_base&))
240 m_stream << *manipulator;
247 LogMessageBase& operator <<(std::ostream& (*manipulator)(std::ostream&))
249 m_stream << *manipulator;
257 return m_stream.str();
263 m_logger->writeMessage(m_stream.str());
267 std::ostringstream m_stream;
275 typedef void (* DeathCallback)(
const std::string& message);
298 m_killMeNow(getMessage());
305 static void setFailureCallback(DeathCallback callback);
310 static DeathCallback getFailureCallback();
316 setFailureCallback(throwException);
323 setFailureCallback(killApplication);
329 static void throwException(
const std::string& errorMessage);
333 static void killApplication(
const std::string& errorMessage);
337 static DeathCallback m_killMeNow;
342 if (level.value < (::imstk::LoggerSynchronous::instance())->getThreshold()) \ 347 ::imstk::LogMessageBase(::imstk::LoggerSynchronous::instance().get(), level.value) 349 #define LOG_IF(level, condition) \ 357 #define CHECK(condition) \ 363 ::imstk::AssertMessage(::imstk::LoggerSynchronous::instance().get()) << "*** Assertion failed: " << \ 364 IMSTK_MAKE_STRING(condition) << " ***" << std::endl << \ 365 " in " << IMSTK_CURRENT_FUNCTION << std::endl << \ 366 " at " << __FILE__ << ":" << __LINE__ << std::endl
void setThreshold(int val)
static void setFailureBehaviorToThrow()
bool writeMessage(const std::string &message)
AssertMessage(const std::shared_ptr< LoggerSynchronous > &logger)
virtual bool writeMessage(const std::string &)
void setOutput(std::shared_ptr< LogOutput > val)
static void startLogger()
For compatibility.
static void setFailureBehaviorToDeath()
AssertMessage(const std::unique_ptr< LoggerSynchronous > &logger)
std::shared_ptr< LogOutput > getOutput() const
void flush()
write the current message to the logger
std::shared_ptr< CacheOutput > getCacheOutput() const
AssertMessage(LoggerSynchronous *logger)
AssertionFailure(const std::string &message)
LoggerSynchronous(std::shared_ptr< LogOutput > output)