void Console::log(const LogMessage& message) { if (message.string().empty()) return; logToDebug(message); logToFile(message); if (m_textCtrl != NULL) logToConsole(message); else m_buffer.push_back(message); }
void Console::logToFile(const LogMessage& message) { #if defined __APPLE__ NSLogWrapper(message.string()); #else IO::FileManager fileManager; const String logDirectory = fileManager.logDirectory(); if (logDirectory.empty()) return; if (!fileManager.exists(logDirectory)) fileManager.makeDirectory(logDirectory); const String logFilePath = fileManager.appendPath(logDirectory, "TrenchBroom.log"); std::fstream logStream(logFilePath.c_str(), std::ios::out | std::ios::app); if (logStream.is_open()) { wxDateTime now = wxDateTime::Now(); logStream << wxGetProcessId() << " " << now.FormatISOCombined(' ') << ": " << message.string() << std::endl; } #endif }
void Console::logToConsole(const LogMessage& message) { long start = m_textCtrl->GetLastPosition(); m_textCtrl->AppendText(message.string()); m_textCtrl->AppendText("\n"); long end = m_textCtrl->GetLastPosition(); switch (message.level()) { case LLDebug: m_textCtrl->SetStyle(start, end, wxTextAttr(*wxLIGHT_GREY, *wxBLACK)); // SetDefaultStyle doesn't work on OS X / Cocoa break; case LLInfo: m_textCtrl->SetStyle(start, end, wxTextAttr(*wxWHITE, *wxBLACK)); // SetDefaultStyle doesn't work on OS X / Cocoa break; case LLWarn: m_textCtrl->SetStyle(start, end, wxTextAttr(*wxYELLOW, *wxBLACK)); // SetDefaultStyle doesn't work on OS X / Cocoa break; case LLError: m_textCtrl->SetStyle(start, end, wxTextAttr(*wxRED, *wxBLACK)); // SetDefaultStyle doesn't work on OS X / Cocoa break; } }