7 #include "imstkLoggerSynchronous.h" 14 #else // not defined(_WIN32) 16 #endif // not defined(_WIN32) 17 #include <unordered_map> 32 m_stream << message << std::endl;
38 throw(
"Default logging not implemented yet");
43 CacheOutput::CacheOutput()
45 m_outFile.open(
"imstk.log");
52 m_outFile << message << std::endl;
53 m_messages.push_back(message);
59 CacheOutput::hasMessages()
const 63 result = !m_messages.empty();
69 CacheOutput::popLastMessage()
73 if (!m_messages.empty())
75 result = m_messages.front();
76 m_messages.pop_front();
83 : m_stream(), m_logger(logger)
85 CHECK(logger) <<
"logger should not be a null pointer";
86 static std::unordered_map<int, std::string> levelNames = {
87 { DEBUG.value,
"DEBUG " },
88 { INFO.value,
"INFO " },
89 { WARNING.value,
"WARNING " },
90 { FATAL.value,
"FATAL " }
92 std::time_t timeStamp;
93 std::time(&timeStamp);
96 localtime_s(&tm, &timeStamp);
98 localtime_r(&timeStamp, &tm);
100 std::string levelName(
"NONE ");
101 if (level >= 0 && level <= FATAL.value)
103 levelName = levelNames[level];
105 char fillChar = m_stream.fill();
106 m_stream << std::setfill(
'0') <<
107 std::setw(2) << 1 + tm.tm_mon <<
"." <<
108 std::setw(2) << tm.tm_mday <<
' ' <<
109 std::setw(2) << tm.tm_hour <<
':' <<
110 std::setw(2) << tm.tm_min <<
':' <<
111 std::setw(2) << tm.tm_sec <<
' ' <<
112 std::setfill(fillChar) <<
114 m_logger->getName() <<
" ";
120 m_killMeNow = callback;
130 AssertMessage::throwException(
const std::string& errorMessage)
133 throw std::runtime_error(errorMessage);
137 AssertMessage::killApplication(
const std::string&)
141 #else // not defined(_WIN32) 143 #endif // not defined(_WIN32) void(* DeathCallback)(const std::string &message)
The type used for the callback function that is triggered after an assertion has failed.
void unlock()
End a thread-safe region.
LogMessageBase(LoggerSynchronous *logger, int level)
void lock()
Start a thread-safe region, where only one thread can execute at a time until a call to the unlock fu...
bool writeMessage(const std::string &message) override
static void setFailureCallback(DeathCallback callback)
static DeathCallback getFailureCallback()
bool writeMessage(const std::string &message) override
StreamOutput(std::ostream &ostream)