#include <Log.h>
Public Member Functions | |
| Log (bool logToFile) | |
| ~Log () | |
| void | Message (std::string msg) |
| void | Message (const char *msg,...) |
| void | DebugMessage (std::string msg) |
| void | DebugMessage (const char *msg,...) |
| void | SetDebugMode (bool debugMode) |
Static Public Member Functions | |
| static bool | OpenLog (bool logToFile) |
| static void | CloseLog () |
Static Public Attributes | |
| static Log * | s_log = NULL |
Private Attributes | |
| bool | m_debugMode |
| std::ofstream | m_logFile |
Definition at line 11 of file Log.h.
| Log::Log | ( | bool | logToFile | ) |
Definition at line 16 of file Log.cpp.
References m_debugMode, and m_logFile.
Referenced by OpenLog().
00016 { 00017 time_t timestamp; 00018 00019 m_debugMode = false; 00020 00021 if (logToFile) { 00022 m_logFile.open("CrownCutlass.log", ios::out); 00023 if (!m_logFile) { 00024 // Can't open log file 00025 cerr << "Warning: Cannot open error.log for write, continuing without logging\n"; 00026 } else { 00027 // Log file is open fine, give opening timestamp 00028 timestamp = time(NULL); 00029 m_logFile << "Log Started: " << ctime(×tamp) << endl; 00030 } 00031 } 00032 }
| Log::~Log | ( | ) |
Definition at line 34 of file Log.cpp.
References m_logFile.
00034 { 00035 time_t timestamp; 00036 00037 // Only need to close logFile if it's open 00038 if (m_logFile) { 00039 // Give closing timestamp 00040 timestamp = time(NULL); 00041 m_logFile << endl << "Log Closed: " << ctime(×tamp) << endl; 00042 00043 // Close log file 00044 m_logFile.close(); 00045 } 00046 }
| void Log::CloseLog | ( | ) | [static] |
| void Log::DebugMessage | ( | const char * | msg, | |
| ... | ||||
| ) |
Definition at line 90 of file Log.cpp.
References m_debugMode, and m_logFile.
00090 { 00091 /* WHY DOESN'T THIS WORK??? 00092 va_list vargList; // This is to handle the variable arguments ... 00093 00094 va_start(vargList, msg); 00095 if (debugMode) { 00096 message(msg, vargList); 00097 } 00098 va_end(vargList); 00099 */ 00100 00101 // Remove this once I figure out how to pass the variable args to the regular message 00102 va_list vargList; // This is to handle the variable arguments ... 00103 char outBuf[1024]; 00104 unsigned short outLen; 00105 00106 if (m_debugMode) { 00107 // This section takes the arguments and puts them into 00108 // the character array. 00109 va_start(vargList, msg); 00110 #if defined (WIN32) 00111 outLen = _vsnprintf(outBuf, sizeof(outBuf), msg, vargList); 00112 #else 00113 outLen = vsnprintf(outBuf, sizeof(outBuf), msg, vargList); 00114 #endif 00115 //outLen = vsprintf(outBuf, msg, vargList); 00116 va_end(vargList); 00117 00118 if (outLen >= sizeof(outBuf)) { 00119 // vsnprintf had to truncate the data, set outLen to correct value 00120 outLen = sizeof(outBuf); 00121 } 00122 00123 if (m_logFile) { 00124 m_logFile << outBuf << endl; 00125 } 00126 00127 cerr << outBuf << endl; 00128 } 00129 }
| void Log::DebugMessage | ( | std::string | msg | ) |
Definition at line 84 of file Log.cpp.
References m_debugMode, and Message().
Referenced by CCListModel::AddItem(), Product::AddProductionPoints(), CityEconomy::AllocateProductionPoints(), CCListBox::CCListBox(), CCListModel::CCListModel(), EconomyScreen::EconomyScreen(), Product::GetPrice(), SoundSystem::LogDebugInfo(), CCListModel::RemoveItem(), SoundSystem::SoundSystem(), CCListModel::~CCListModel(), and SoundSystem::~SoundSystem().
00084 { 00085 if (m_debugMode) { 00086 Message(msg); 00087 } 00088 }
| void Log::Message | ( | const char * | msg, | |
| ... | ||||
| ) |
Definition at line 56 of file Log.cpp.
References m_logFile.
00056 { 00057 va_list vargList; // This is to handle the variable arguments ... 00058 char outBuf[1024]; 00059 unsigned short outLen; 00060 00061 // This section takes the arguments and puts them into 00062 // the character array. 00063 va_start(vargList, msg); 00064 #if defined (WIN32) 00065 outLen = _vsnprintf(outBuf, sizeof(outBuf), msg, vargList); 00066 #else 00067 outLen = vsnprintf(outBuf, sizeof(outBuf), msg, vargList); 00068 #endif 00069 //outLen = vsprintf(outBuf, msg, vargList); 00070 va_end(vargList); 00071 00072 if (outLen >= sizeof(outBuf)) { 00073 // vsnprintf had to truncate the data, set outLen to correct value 00074 outLen = sizeof(outBuf); 00075 } 00076 00077 if (m_logFile) { 00078 m_logFile << outBuf << endl; 00079 } 00080 00081 cerr << outBuf << endl; 00082 }
| void Log::Message | ( | std::string | msg | ) |
Definition at line 48 of file Log.cpp.
References m_logFile.
Referenced by ResourceManager::AcquireRandom(), Ship::AcquireResource(), Cargo::AddCargo(), BuildTexture(), StateCity::Buy(), StateDone::Buy(), Economy::BuyProduct(), Terrain::CalcHeight(), ShipResource::CalcMassMomentInertia(), Config::CheckExtensions(), CityManager::CityManager(), Config::CloseConfig(), Config::Config(), Economy::CreateEconomy(), CCGui::CreateGui(), DebugMessage(), CityEconomy::DecreaseSize(), Economy::DestroyEconomy(), CCGui::DestroyGui(), SkyDome::Draw(), Ship::Dump(), Point::Dump(), Player::Dump(), Cargo::Dump(), BuildingList::Dump(), Building::Dump(), Battle::EnemyHit(), TCallback< StateNewGame >::Execute(), Cargo::FillRandom(), FontResource::FontResource(), CCListModel::getElementAt(), CityEconomy::IncreaseSize(), init(), Timer::Initialize(), StateSailing::Initialize(), SoundSystem::Initialize(), ResourceManager::Initialize(), SoundEffect::InitializeSource(), StateCity::InitMenu(), TextureResource::Load(), SoundResource::Load(), ShipResource::Load(), FontResource::Load(), Cargo::Load(), CityManager::LoadCityConfig(), ResourceManager::LoadXMLFile(), Config::LogConfig(), ResourceManager::LogDebugInfo(), IGameState::Loop(), main(), MainMenu::MainMenu(), Model::objFirstPass(), Model::objLoad(), Model::objSecondPass(), Config::OpenConfig(), OpenLog(), CityManager::ParseClusters(), SoundEffect::Play(), Battle::PlayerHit(), IGameState::PrepareStateSwitch(), prepExit(), Product::Product(), Ship::ReleaseResource(), ResourceManager::ResourceManager(), ISound::RevokeSource(), StateDone::SackPlayer(), StateCity::Sell(), StateDone::Sell(), Economy::SellProduct(), IGameState::SetCurrentPtr(), IGameState::SetMainMenu(), StateDone::SetMenuQtys(), StateDone::SetupMenu(), ShipResource::ShipResource(), Timer::Shutdown(), SoundSystem::Shutdown(), ResourceManager::Shutdown(), Ship::SinkShip(), SoundResource::SoundResource(), SoundSystem::SoundSystem(), Model::startList(), StateBattle::StateBattle(), StateCity::StateCity(), StateDone::StateDone(), StateNewGame::StateNewGame(), StateSailing::StateSailing(), IGameState::SwitchStates(), IGameState::TakeScreenshot(), Terrain::Terrain(), TextureResource::TextureResource(), StateSailing::Timer(), Battle::Timer(), TextureResource::Unload(), SoundResource::Unload(), ShipResource::Unload(), FontResource::Unload(), Battle::~Battle(), Cargo::~Cargo(), CCGui::~CCGui(), CityManager::~CityManager(), FontFactory::~FontFactory(), FontResource::~FontResource(), MainMenu::~MainMenu(), Ocean::~Ocean(), ResourceManager::~ResourceManager(), ShipFactory::~ShipFactory(), ShipResource::~ShipResource(), SoundFactory::~SoundFactory(), SoundResource::~SoundResource(), SoundSystem::~SoundSystem(), StateBattle::~StateBattle(), StateDone::~StateDone(), StateNewGame::~StateNewGame(), StateSailing::~StateSailing(), Terrain::~Terrain(), TextureFactory::~TextureFactory(), and TextureResource::~TextureResource().
00048 { 00049 if (m_logFile) { 00050 m_logFile << msg << endl << endl; 00051 } 00052 00053 cerr << msg << endl << endl; 00054 }
| bool Log::OpenLog | ( | bool | logToFile | ) | [static] |
Definition at line 135 of file Log.cpp.
References Log(), Message(), and s_log.
Referenced by main().
00135 { 00136 // Make sure s_log hasn't already been initialized 00137 if (s_log != NULL) { 00138 s_log->Message("Warning: Multiple calls to OpenLog()"); 00139 return false; 00140 } 00141 00142 s_log = new Log(logToFile); 00143 return true; 00144 }
| void Log::SetDebugMode | ( | bool | debugMode | ) |
Definition at line 131 of file Log.cpp.
References m_debugMode.
Referenced by Config::Config().
00131 { 00132 m_debugMode = debugMode; 00133 }
bool Log::m_debugMode [private] |
std::ofstream Log::m_logFile [private] |
Log * Log::s_log = NULL [static] |
Definition at line 30 of file Log.h.
Referenced by ResourceManager::AcquireRandom(), Ship::AcquireResource(), Cargo::AddCargo(), CCListModel::AddItem(), Product::AddProductionPoints(), CityEconomy::AllocateProductionPoints(), BuildTexture(), StateCity::Buy(), StateDone::Buy(), Economy::BuyProduct(), Terrain::CalcHeight(), ShipResource::CalcMassMomentInertia(), CCListBox::CCListBox(), CCListModel::CCListModel(), Config::CheckExtensions(), CityManager::CityManager(), Config::CloseConfig(), CloseLog(), Config::Config(), Economy::CreateEconomy(), CCGui::CreateGui(), CityEconomy::DecreaseSize(), Economy::DestroyEconomy(), CCGui::DestroyGui(), SkyDome::Draw(), Ship::Dump(), Point::Dump(), Player::Dump(), Cargo::Dump(), BuildingList::Dump(), Building::Dump(), Economy::Economy(), EconomyScreen::EconomyScreen(), Battle::EnemyHit(), TCallback< StateNewGame >::Execute(), Cargo::FillRandom(), FontResource::FontResource(), CCListModel::getElementAt(), Product::GetPrice(), CityEconomy::IncreaseSize(), init(), Timer::Initialize(), StateSailing::Initialize(), SoundSystem::Initialize(), ResourceManager::Initialize(), SoundEffect::InitializeSource(), StateCity::InitMenu(), Ship::Load(), TextureResource::Load(), SoundResource::Load(), ShipResource::Load(), FontResource::Load(), Player::Load(), Cargo::Load(), CityManager::LoadCityConfig(), MainMenu::LoadGame(), ResourceManager::LoadXMLFile(), Config::LogConfig(), SoundSystem::LogDebugInfo(), ResourceManager::LogDebugInfo(), IGameState::Loop(), main(), MainMenu::MainMenu(), Model::objFirstPass(), Model::objLoad(), Model::objSecondPass(), Config::OpenConfig(), OpenLog(), Economy::ParseCityProducts(), CityManager::ParseClusters(), SoundEffect::Play(), Battle::PlayerHit(), IGameState::PrepareStateSwitch(), prepExit(), Product::Product(), Ship::ReleaseResource(), CCListModel::RemoveItem(), ResourceManager::ResourceManager(), ISound::RevokeSource(), StateDone::SackPlayer(), StateCity::Sell(), StateDone::Sell(), Economy::SellProduct(), IGameState::SetCurrentPtr(), IGameState::SetMainMenu(), StateDone::SetMenuQtys(), StateDone::SetupMenu(), ShipResource::ShipResource(), Timer::Shutdown(), SoundSystem::Shutdown(), ResourceManager::Shutdown(), Ship::SinkShip(), SoundResource::SoundResource(), SoundSystem::SoundSystem(), Model::startList(), StateBattle::StateBattle(), StateCity::StateCity(), StateDone::StateDone(), StateNewGame::StateNewGame(), StateSailing::StateSailing(), IGameState::SwitchStates(), IGameState::TakeScreenshot(), Terrain::Terrain(), TextureResource::TextureResource(), StateSailing::Timer(), Battle::Timer(), TextureResource::Unload(), SoundResource::Unload(), ShipResource::Unload(), FontResource::Unload(), MainMenu::Update(), Battle::~Battle(), Cargo::~Cargo(), CCGui::~CCGui(), CCListModel::~CCListModel(), CityManager::~CityManager(), FontFactory::~FontFactory(), FontResource::~FontResource(), MainMenu::~MainMenu(), Ocean::~Ocean(), ResourceManager::~ResourceManager(), ShipFactory::~ShipFactory(), ShipResource::~ShipResource(), SoundFactory::~SoundFactory(), SoundResource::~SoundResource(), SoundSystem::~SoundSystem(), StateBattle::~StateBattle(), StateDone::~StateDone(), StateNewGame::~StateNewGame(), StateSailing::~StateSailing(), Terrain::~Terrain(), TextureFactory::~TextureFactory(), and TextureResource::~TextureResource().
1.4.7