ManaPlus
Public Member Functions | Private Attributes
Logger Class Reference

#include <logger.h>

Public Member Functions

 Logger ()
 
 ~Logger ()
 
void setLogFile (const std::string &logFilename)
 
void setLogToStandardOut (const bool value)
 
void log (const char *const log_text,...)
 
void assertLog (const char *const log_text,...)
 
void log_r (const char *const log_text,...)
 
void log1 (const char *const log_text)
 
void log (const std::string &str)
 
void flush ()
 
void dlog (const std::string &str)
 
void dlog2 (const std::string &str, const int pos, const char *const comment)
 
void setDebugLog (const bool n)
 
void setReportUnimplemented (const bool n)
 
void error (const std::string &error_text) __attribute__((noreturn))
 
void safeError (const std::string &error_text) __attribute__((noreturn))
 
void unimplemented (const int id)
 
void unimplemented (const int id, const int id2)
 
void unimplemented (const uint32_t id, const uint32_t id2, const uint32_t id3) const
 

Private Attributes

std::ofstream mLogFile
 
std::vector< std::string > mDelayedLog
 
SDL_mutex * mMutex
 
volatile bool mThreadLocked
 
bool mLogToStandardOut
 
bool mDebugLog
 
bool mReportUnimplemented
 

Detailed Description

The Log Class : Useful to write debug or info messages

Definition at line 67 of file logger.h.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( )

Constructor.

Definition at line 97 of file logger.cpp.

97  :
98  mLogFile(),
99  mDelayedLog(),
100  mMutex(SDL_CreateMutex()),
101  mThreadLocked(false),
102  mLogToStandardOut(true),
103  mDebugLog(false),
104  mReportUnimplemented(false)
105 {
106 #if defined __native_client__ && defined(NACL_LOG)
107  std::cout.setf(std::ios_base::unitbuf);
108 #endif // defined __native_client__ && defined(NACL_LOG)
109 }
volatile bool mThreadLocked
Definition: logger.h:217
bool mLogToStandardOut
Definition: logger.h:218
std::vector< std::string > mDelayedLog
Definition: logger.h:215
SDL_mutex * mMutex
Definition: logger.h:216
bool mReportUnimplemented
Definition: logger.h:220
bool mDebugLog
Definition: logger.h:219
std::ofstream mLogFile
Definition: logger.h:214

◆ ~Logger()

Logger::~Logger ( )

Destructor, closes log file.

Definition at line 111 of file logger.cpp.

References mLogFile, and mMutex.

112 {
113  if (mLogFile.is_open())
114  mLogFile.close();
115  SDL_DestroyMutex(mMutex);
116 }
SDL_mutex * mMutex
Definition: logger.h:216
std::ofstream mLogFile
Definition: logger.h:214

Member Function Documentation

◆ assertLog()

void Logger::assertLog ( const char *const  log_text,
  ... 
)

Enters a message in the log. The message will be timestamped.

Definition at line 280 of file logger.cpp.

References CAST_SIZE, CAST_U32, DATESTREAM, Settings::disableLoggingInGame, DebugMessageListener::distributeEvent(), mLogFile, mLogToStandardOut, settings, ServerCommandType::size, and SPECIALLOG.

Referenced by compareSDLVersions(), compareVersions(), VirtFs::create_rwops(), EventsManager::logEvent(), VirtFs::FsDir::rwops_seek(), VirtFs::FsZip::rwops_seek(), setLogToStandardOut(), and WhoIsOnline::slowLogic().

281 {
283  return;
284 
285  unsigned size = 1024;
286  if (strlen(log_text) * 3 > size)
287  size = CAST_U32(strlen(log_text) * 3);
288 
289  char* buf = new char[CAST_SIZE(size + 1)];
290  va_list ap;
291 
292  // Use a temporary buffer to fill in the variables
293  va_start(ap, log_text);
294  vsnprintf(buf, size, log_text, ap);
295  buf[size] = 0;
296  va_end(ap);
297 
298  // Get the current system time
299  timeval tv;
300  gettimeofday(&tv, nullptr);
301 
302  // Print the log entry
303  std::stringstream timeStr;
304  DATESTREAM
305  SPECIALLOG(buf)
306 
307  if (mLogFile.is_open())
308  mLogFile << timeStr.str() << buf << std::endl;
309 
310  if (mLogToStandardOut)
311  std::cout << timeStr.str() << buf << std::endl;
312 
314 
315  // Delete temporary buffer
316  delete [] buf;
317 }
#define CAST_U32
Definition: cast.h:30
Settings settings
Definition: settings.cpp:31
bool mLogToStandardOut
Definition: logger.h:218
#define SPECIALLOG(x)
Definition: logger.cpp:73
bool disableLoggingInGame
Definition: settings.h:158
#define CAST_SIZE
Definition: cast.h:33
static void distributeEvent(const std::string &msg)
std::ofstream mLogFile
Definition: logger.h:214
#define DATESTREAM
Definition: logger.cpp:80

◆ dlog()

void Logger::dlog ( const std::string &  str)

Enters debug message in the log. The message will be timestamped.

Definition at line 143 of file logger.cpp.

References DATESTREAM, DSPECIALLOG, mDebugLog, mLogFile, and mLogToStandardOut.

Referenced by Net::MessageIn::readBytes(), and setLogToStandardOut().

144 {
145  if (!mDebugLog)
146  return;
147 
148  // Get the current system time
149  timeval tv;
150  gettimeofday(&tv, nullptr);
151 
152  // Print the log entry
153  std::stringstream timeStr;
154  DATESTREAM
155  DSPECIALLOG(str.c_str())
156 
157  if (mLogFile.is_open())
158  mLogFile << timeStr.str() << str << std::endl;
159 
160  if (mLogToStandardOut)
161  std::cout << timeStr.str() << str << std::endl;
162 }
bool mLogToStandardOut
Definition: logger.h:218
bool mDebugLog
Definition: logger.h:219
#define DSPECIALLOG(x)
Definition: logger.cpp:74
std::ofstream mLogFile
Definition: logger.h:214
#define DATESTREAM
Definition: logger.cpp:80

◆ dlog2()

void Logger::dlog2 ( const std::string &  str,
const int  pos,
const char *const  comment 
)

Definition at line 164 of file logger.cpp.

References DATESTREAM, DSPECIALLOG, mDebugLog, mLogFile, and mLogToStandardOut.

Referenced by setLogToStandardOut().

167 {
168  if (!mDebugLog)
169  return;
170 
171  // Get the current system time
172  timeval tv;
173  gettimeofday(&tv, nullptr);
174 
175  // Print the log entry
176  std::stringstream timeStr;
177  DATESTREAM
178  DSPECIALLOG(str.c_str())
179 
180  if (mLogFile.is_open())
181  {
182  if (comment != nullptr)
183  {
184  mLogFile << timeStr.str();
185  mLogFile.fill('0');
186  mLogFile.width(4);
187  mLogFile << pos << " ";
188  mLogFile << str << ": " << comment << std::endl;
189  }
190  else
191  {
192  mLogFile << timeStr.str();
193  mLogFile.fill('0');
194  mLogFile.width(4);
195  mLogFile << pos << " ";
196  mLogFile << str << std::endl;
197  }
198  }
199 
200  if (mLogToStandardOut)
201  {
202  if (comment != nullptr)
203  {
204  std::cout << timeStr.str();
205  std::cout.fill('0');
206  std::cout.width(4);
207  std::cout << pos << " ";
208  std::cout << str << ": " << comment << std::endl;
209  }
210  else
211  {
212  std::cout << timeStr.str();
213  std::cout.fill('0');
214  std::cout.width(4);
215  std::cout << pos << " ";
216  std::cout << str << std::endl;
217  }
218  }
219 }
bool mLogToStandardOut
Definition: logger.h:218
bool mDebugLog
Definition: logger.h:219
#define DSPECIALLOG(x)
Definition: logger.cpp:74
std::ofstream mLogFile
Definition: logger.h:214
#define DATESTREAM
Definition: logger.cpp:80

◆ error()

void Logger::error ( const std::string &  error_text)

Log an error and quit. The error will pop-up on Windows and Mac, and will be printed to standard error everywhere else.

Definition at line 415 of file logger.cpp.

References log(), and Actions::msg().

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), Font::Font(), Client::gameInit(), Dirs::initConfigDir(), Dirs::initLocalDataDir(), ConfigManager::initServerConfig(), Dirs::initTempDir(), Dirs::initUsersDir(), ModernOpenGLGraphics::postInit(), setReportUnimplemented(), and GraphicsManager::setVideoMode().

416 {
417  log("Error: %s", error_text.c_str());
418 #ifdef USE_SDL2
419  SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
420  "Error",
421  error_text.c_str(),
422  nullptr);
423 #else // USE_SDL2
424 #ifdef WIN32
425  MessageBox(nullptr, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
426 #elif defined __APPLE__
427 // Str255 msg;
428 // CFStringRef error;
429 // error = CFStringCreateWithCString(nullptr,
430 // error_text.c_str(),
431 // kCFStringEncodingMacRoman);
432 // CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman);
433 // StandardAlert(kAlertStopAlert,
434 // (const unsigned char*)"\pError",
435 // (ConstStr255Param) msg, nullptr, nullptr);
436 #elif defined(__linux__) || defined(_linux)
437  std::cerr << "Error: " << error_text << std::endl;
438  const std::string msg("xmessage \"Error happened. "
439  "Please see log file for more information.\"");
440  if (system(msg.c_str()) == -1)
441  std::cerr << "Error: " << error_text << std::endl;
442 #else // WIN32
443 
444  std::cerr << "Error: " << error_text << std::endl;
445 #endif // WIN32
446 #endif // USE_SDL2
447 
448  exit(1);
449 }
bool msg(InputEvent &event)
Definition: chat.cpp:38
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ flush()

void Logger::flush ( )

Definition at line 365 of file logger.cpp.

References FOR_EACH, mDelayedLog, mLogFile, mMutex, and mThreadLocked.

Referenced by setLogToStandardOut(), and Gui::slowLogic().

366 {
367  if (!mThreadLocked)
368  {
369  SDL_mutexP(mMutex);
370  FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, mDelayedLog)
371  mLogFile << *it << std::endl;
372  mDelayedLog.clear();
373  SDL_mutexV(mMutex);
374  }
375 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
volatile bool mThreadLocked
Definition: logger.h:217
std::vector< std::string > mDelayedLog
Definition: logger.h:215
SDL_mutex * mMutex
Definition: logger.h:216
std::ofstream mLogFile
Definition: logger.h:214

◆ log() [1/2]

void Logger::log ( const char *const  log_text,
  ... 
)

Enters a message in the log. The message will be timestamped.

Definition at line 243 of file logger.cpp.

References CAST_SIZE, CAST_U32, DATESTREAM, Settings::disableLoggingInGame, mLogFile, mLogToStandardOut, settings, ServerCommandType::size, and SPECIALLOG.

Referenced by ChangeEmailDialog::action(), ChangePasswordDialog::action(), RegisterDialog::action(), anonymous_namespace{client.cpp}::LoginListener::action(), Map::addAnimation(), Particle::addEffect(), ParticleEngine::addEffect(), Map::addExtraLayer(), MapReader::addLayerToList(), ResourceManager::addResource(), applyEffectByOption(), applyEffectByOption1(), ConfigManager::backupConfig(), ModernOpenGLGraphics::bindElementBuffer(), GettextHelper::bindTextDomain(), SafeOpenGLImageHelper::bindTexture(), ResourceManager::cleanUp(), MobileOpenGLGraphics::clearScreen(), NormalOpenGLGraphics::clearScreen(), NullOpenGLGraphics::clearScreen(), Joystick::close(), Ea::Network::connect(), AtlasManager::convertAtlas(), AtlasManager::convertEmptyAtlas(), SDLInput::convertMouseButton(), SafeOpenGLImageHelper::convertSurface(), SafeOpenGLImageHelper::convertSurfaceNormalize(), EAthena::BeingRecv::createBeing2(), ShadersManager::createProgram(), AtlasManager::createSDLAtlas(), ShadersManager::createShader(), GraphicsManager::createTextureSampler(), SDL::createThread(), debugCallback(), Resource::decRef(), ResourceManager::deleteInstance(), ResourceManager::deleteResourceManager(), destroyGuiWindows(), Cpu::detect(), GraphicsManager::detectGraphics(), GraphicsManager::detectPixelSize(), TmwAthena::Network::dispatchMessages(), EAthena::Network::dispatchMessages(), Font::doClean(), Actions::doSit(), ServerDialog::downloadUpdate(), MobileOpenGL2Graphics::drawLineArrays(), ModernOpenGLGraphics::drawLineArrays(), dumpLibs(), dumpLinkedSdlVersion(), MobileOpenGL2Graphics::dumpSettings(), MobileOpenGLGraphics::dumpSettings(), ModernOpenGLGraphics::dumpSettings(), NormalOpenGLGraphics::dumpSettings(), dumpSizes(), Being::dumpSprites(), ImageHelper::dumpSurfaceFormat(), Dye::Dye(), DyePalette::DyePalette(), error(), SoundManager::fadeOutMusic(), Font::Font(), Net::MessageIn::fromServerDirection(), Game::Game(), Client::gameClear(), Client::gameExec(), Client::gameInit(), ImageSet::get(), ResourceManager::get(), SpriteDef::getAction(), SDL::getAllVideoModes(), Theme::getColor(), UserPalette::getColor(), ScrollArea::getImageByState(), Graphics::getMemoryUsage(), Theme::getProgressColor(), SafeOpenGLImageHelper::glLoad(), PIS_dotdotdot::ignore(), PIS_blinkname::ignore(), Image::Image(), Resource::incRef(), SoundManager::info(), IPC::init(), SoundManager::init(), Joystick::init(), Configuration::init(), EggSelectionDialog::initButtons(), Dirs::initConfigDir(), Client::initConfigListeners(), ConfigManager::initConfiguration(), initDefaultThemePath(), GraphicsManager::initGraphics(), GettextHelper::initLang(), Dirs::initRootDir(), Dirs::initScreenshotDir(), ConfigManager::initServerConfig(), Client::initSoundManager(), Client::initTradeFilter(), Dirs::initUpdatesDir(), Dye::instantiate(), SafeOpenGLImageHelper::invalidate(), OpenGLImageHelper::invalidate(), TestMain::invokeModernOpenGLRenderTest(), TestMain::invokeNormalOpenGLRenderTest(), TestMain::invokeSafeOpenGLRenderTest(), TestMain::invokeSoftwareRenderTest(), TestMain::invokeTest4(), itemTypeFromString(), PoParser::load(), CharDB::load(), anonymous_namespace{musicloader.cpp}::ResourceLoader::load(), ImageHelper::load(), SafeOpenGLImageHelper::load(), Theme::load(), Theme::loadColors(), Client::loadData(), VirtFs::FsDir::loadFile(), VirtFs::FsZip::loadFile(), Font::loadFont(), ColorDB::loadHair(), AtlasManager::loadImages(), Theme::loadInfo(), TranslationManager::loadLang(), UpdaterWindow::loadLocalUpdates(), PaletteDB::loadPalette(), ImageHelper::loadPng(), loadQuest(), loadReplaceLayer(), ServerDialog::loadServers(), VirtFs::loadTextFile(), VirtFs::loadTextFileString(), loadTxtFile(), loadUnit(), UpdaterWindow::loadUpdates(), DeadDB::loadXmlFile(), StatDb::loadXmlFile(), GroupDb::loadXmlFile(), ItemFieldDb::loadXmlFile(), PETDB::loadXmlFile(), SkillUnitDb::loadXmlFile(), ModDB::loadXmlFile(), ItemOptionDb::loadXmlFile(), UnitsDb::loadXmlFile(), AvatarDB::loadXmlFile(), HorseDB::loadXmlFile(), CommandsDB::loadXmlFile(), ElementalDb::loadXmlFile(), HomunculusDB::loadXmlFile(), MercenaryDB::loadXmlFile(), MonsterDB::loadXmlFile(), ItemDB::loadXmlFile(), EmoteDB::loadXmlFile(), NPCDB::loadXmlFile(), EffectManager::loadXmlFile(), StatusEffectDB::loadXmlFile(), loadXMLFile(), SkillDialog::loadXmlFile(), Mutex::lock(), log(), GraphicsManager::logError(), EventsManager::logEvent(), ServerDialog::logic(), Joystick::logic(), UpdaterWindow::logic(), Ea::LoginHandler::loginOrRegister(), ResourceManager::logResource(), ResourceManager::logResources(), GraphicsManager::logString(), Client::logVars(), GraphicsManager::logVersion(), VirtFs::mountDirInternal(), VirtFs::mountDirSilent(), VirtFs::mountDirSilent2(), VirtFs::mountZip(), VirtFs::mountZip2(), Joystick::open(), Font::openFont(), ParticleEmitter::ParticleEmitter(), SoundManager::playGuiSfx(), SoundManager::playSfx(), Popup::Popup(), MobileOpenGL2Graphics::postInit(), ModernOpenGLGraphics::postInit(), ServerDialog::postInit(), Theme::prepareThemePath(), Cpu::printFlags(), MemoryManager::printMemory(), Ea::BeingRecv::processBeingMove3(), EAthena::CashShopRecv::processCashShopSchedule(), EAthena::CashShopRecv::processCashShopTabPriceList(), EAthena::CharServerRecv::processCharCharacters(), TmwAthena::CharServerRecv::processCharLogin(), EAthena::CharServerRecv::processCharLogin(), TmwAthena::GeneralRecv::processConnectionProblem(), EAthena::GeneralRecv::processConnectionProblem(), TmwAthena::LoginRecv::processLoginData(), EAthena::LoginRecv::processLoginData(), Ea::LoginRecv::processLoginError(), EAthena::LoginRecv::processLoginError2(), EAthena::MailRecv::processMailList(), TmwAthena::GameRecv::processMapLogin(), EAthena::GameRecv::processMapLogin(), TmwAthena::InventoryRecv::processPlayerEquipment(), TmwAthena::InventoryRecv::processPlayerInventory(), TmwAthena::InventoryRecv::processPlayerStorage(), TmwAthena::InventoryRecv::processPlayerStorageEquip(), Ea::PlayerRecv::processPlayerWarp(), EAthena::MailRecv::processReadMail(), TmwAthena::LoginRecv::processServerVersion(), EAthena::LoginRecv::processServerVersion(), EAthena::SkillRecv::processSkillFailed(), TmwAthena::SkillRecv::processSkillFailed(), TmwAthena::TradeRecv::processTradeItemAddResponse(), Ea::LoginRecv::processUpdateHost(), EAthena::LoginRecv::processUpdateHost2(), MStack< ClipRect >::push(), VirtFs::ZipReader::readArchiveInfo(), readColor(), Net::MessageIn::readCoordinatePair(), Net::MessageIn::readCoordinates(), MapReader::readLayer(), BeingCommon::readObjectNodes(), Theme::readSkin(), MapReader::readTileset(), TestMain::readValue2(), readXmlIntMap(), readXmlIntVector(), readXmlStringMap(), Map::reduce(), EAthena::Network::registerFakeHandlers(), Configuration::reInit(), Configuration::removeListener(), Configuration::removeOldKeys(), safeError(), Map::saveExtraLayer(), Game::saveScreenshot(), Being::setAction(), Image::setAlpha(), Desktop::setBestFittingWallpaper(), setBrandingDefaults(), CharSelectDialog::setCharacter(), setConfigDefaults(), setConfigDefaults2(), setEnv(), setFeaturesDefaults(), GraphicsManager::setGLVersion(), WindowManager::setIcon(), ComplexInventory::setItem(), setLogToStandardOut(), Graphics::setMainFlags(), Graphics::setOpenGLMode(), setPathsDefaults(), Graphics::setScale(), NpcDialog::setSkin(), ActorSprite::setStatusEffectBlock(), BeingInfo::setTargetCursorSize(), Gui::setUseCustomCursor(), GraphicsManager::setVideoMode(), IPC::start(), Net::Download::start(), Client::stateSwitchLogin1(), IPC::stop(), SubImage::SubImage(), SoundManager::testAudio(), TranslationManager::translateFile(), unimplemented(), Mutex::unlock(), VirtFs::unmountDirInternal(), VirtFs::unmountDirSilent(), VirtFs::unmountDirSilent2(), VirtFs::unmountZip(), VirtFs::unmountZip2(), GraphicsManager::updateLimits(), Graphics::updateMemoryInfo(), GraphicsManager::updatePlanformExtensions(), EAthena::updateProtocol(), GraphicsManager::updateTextureCompressionFormat(), useButton2FromItemType(), useButtonFromItemType(), Graphics::videoInfo(), Window::Window(), TestMain::writeConfig(), ConfigurationObject::writeToXML(), Image::~Image(), Net::MessageIn::~MessageIn(), Popup::~Popup(), SubImage::~SubImage(), and Window::~Window().

244 {
246  return;
247 
248  unsigned size = 1024;
249  if (strlen(log_text) * 3 > size)
250  size = CAST_U32(strlen(log_text) * 3);
251 
252  char* buf = new char[CAST_SIZE(size + 1)];
253  va_list ap;
254 
255  // Use a temporary buffer to fill in the variables
256  va_start(ap, log_text);
257  vsnprintf(buf, size, log_text, ap);
258  buf[size] = 0;
259  va_end(ap);
260 
261  // Get the current system time
262  timeval tv;
263  gettimeofday(&tv, nullptr);
264 
265  // Print the log entry
266  std::stringstream timeStr;
267  DATESTREAM
268  SPECIALLOG(buf)
269 
270  if (mLogFile.is_open())
271  mLogFile << timeStr.str() << buf << std::endl;
272 
273  if (mLogToStandardOut)
274  std::cout << timeStr.str() << buf << std::endl;
275 
276  // Delete temporary buffer
277  delete [] buf;
278 }
#define CAST_U32
Definition: cast.h:30
Settings settings
Definition: settings.cpp:31
bool mLogToStandardOut
Definition: logger.h:218
#define SPECIALLOG(x)
Definition: logger.cpp:73
bool disableLoggingInGame
Definition: settings.h:158
#define CAST_SIZE
Definition: cast.h:33
std::ofstream mLogFile
Definition: logger.h:214
#define DATESTREAM
Definition: logger.cpp:80

◆ log() [2/2]

void Logger::log ( const std::string &  str)

Enters a message in the log. The message will be timestamped.

Definition at line 137 of file logger.cpp.

References log().

138 {
139  log("%s", str.c_str());
140 }
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ log1()

void Logger::log1 ( const char *const  log_text)

Enters a message in the log. The message will be timestamped.

Definition at line 222 of file logger.cpp.

References DATESTREAM, Settings::disableLoggingInGame, mLogFile, mLogToStandardOut, settings, and SPECIALLOG.

Referenced by ConnectionDialog::action(), anonymous_namespace{client.cpp}::LoginListener::action(), Map::addExtraLayer(), LayoutArray::align(), ConfigManager::backupConfig(), ResourceManager::clearDeleted(), SoundManager::close(), Ea::Network::connect(), MapReader::createEmptyMap(), GraphicsManager::createTextureSampler(), ResourceManager::deleteInstance(), GraphicsManager::detectGraphics(), Actions::doSit(), EffectManager::EffectManager(), Client::gameClear(), Client::gameExec(), Client::gameInit(), SDL::getAllVideoModes(), EventsManager::handleCommonEvents(), EventsManager::handleEvents(), SoundManager::info(), SoundManager::init(), Configuration::init(), Client::initConfigListeners(), ConfigManager::initConfiguration(), GraphicsManager::initOpenGLFunctions(), Dirs::initUpdatesDir(), LanguageDb::load(), PaletteDB::load(), SoundDB::load(), TextDb::load(), WeaponsDB::load(), ModDB::load(), BadgesDB::load(), StatDb::load(), GroupDb::load(), ItemFieldDb::load(), DeadDB::load(), ItemOptionDb::load(), PETDB::load(), SkillUnitDb::load(), AvatarDB::load(), UnitsDb::load(), QuestDb::load(), CharDB::load(), ElementalDb::load(), HomunculusDB::load(), MercenaryDB::load(), MonsterDB::load(), NPCDB::load(), CommandsDB::load(), HorseDB::load(), ItemDB::load(), MapDB::load(), NetworkDb::load(), NpcDialogDB::load(), ColorDB::load(), EmoteDB::load(), StatusEffectDB::load(), loadHostsGroup(), UpdaterWindow::loadNews(), UpdaterWindow::loadPatch(), loadReplaceLayer(), ServerDialog::loadServers(), EmoteDB::loadSpecialXmlFile(), LocalPlayer::LocalPlayer(), Joystick::open(), ParticleEmitter::ParticleEmitter(), Gui::postInit(), EAthena::GuildRecv::processGuildMemberList(), EAthena::GuildRecv::processGuildPosNameList(), TmwAthena::PartyRecv::processPartyInfo(), EAthena::PartyRecv::processPartyInfo(), Ea::PlayerRecv::processPlayerWarp(), Ea::LoginRecv::processUpdateHost(), EAthena::LoginRecv::processUpdateHost2(), Theme::readSkin(), Map::saveExtraLayer(), Game::saveScreenshot(), setLogToStandardOut(), Graphics::setOpenGLMode(), ParticleEngine::setupEngine(), Net::Download::start(), Client::stateSwitchLogin1(), ConfigManager::storeSafeParameters(), PaletteDB::unload(), WeaponsDB::unload(), StatDb::unload(), ModDB::unload(), BadgesDB::unload(), GroupDb::unload(), LanguageDb::unload(), ItemFieldDb::unload(), SoundDB::unload(), AvatarDB::unload(), UnitsDb::unload(), ItemOptionDb::unload(), TextDb::unload(), MercenaryDB::unload(), ElementalDb::unload(), MonsterDB::unload(), PETDB::unload(), NPCDB::unload(), SkillUnitDb::unload(), HomunculusDB::unload(), CommandsDB::unload(), ItemDB::unload(), CharDB::unload(), QuestDb::unload(), DeadDB::unload(), NetworkDb::unload(), NpcDialogDB::unload(), HorseDB::unload(), EmoteDB::unload(), MapDB::unload(), ColorDB::unload(), StatusEffectDB::unload(), GraphicsManager::updateDebugLog(), GraphicsManager::updateExtensions(), GraphicsManager::updatePlanformExtensions(), GraphicsManager::updateTextureCompressionFormat(), GraphicsManager::updateTextureFormat(), Graphics::videoInfo(), Configuration::write(), ItemShortcut::~ItemShortcut(), and LocalPlayer::~LocalPlayer().

223 {
225  return;
226 
227  // Get the current system time
228  timeval tv;
229  gettimeofday(&tv, nullptr);
230 
231  // Print the log entry
232  std::stringstream timeStr;
233  DATESTREAM
234  SPECIALLOG(buf)
235 
236  if (mLogFile.is_open())
237  mLogFile << timeStr.str() << buf << std::endl;
238 
239  if (mLogToStandardOut)
240  std::cout << timeStr.str() << buf << std::endl;
241 }
Settings settings
Definition: settings.cpp:31
bool mLogToStandardOut
Definition: logger.h:218
#define SPECIALLOG(x)
Definition: logger.cpp:73
bool disableLoggingInGame
Definition: settings.h:158
std::ofstream mLogFile
Definition: logger.h:214
#define DATESTREAM
Definition: logger.cpp:80

◆ log_r()

void Logger::log_r ( const char *const  log_text,
  ... 
)

Enters a message in the log (thread safe).

Definition at line 319 of file logger.cpp.

References CAST_SIZE, CAST_U32, DATESTREAM, Settings::disableLoggingInGame, mDelayedLog, mLogFile, mLogToStandardOut, mMutex, mThreadLocked, settings, ServerCommandType::size, and SPECIALLOG.

Referenced by IPC::acceptLoop(), Net::Download::downloadThread(), TcpNet::open(), Ea::Network::realConnect(), Ea::Network::receive(), Ea::Network::setError(), setLogToStandardOut(), and xmlErrorLogger().

320 {
322  return;
323 
324  SDL_mutexP(mMutex);
325 
326  unsigned size = 1024;
327  if (strlen(log_text) * 3 > size)
328  size = CAST_U32(strlen(log_text) * 3);
329 
330  char* buf = new char[CAST_SIZE(size + 1)];
331  va_list ap;
332 
333  // Use a temporary buffer to fill in the variables
334  va_start(ap, log_text);
335  vsnprintf(buf, size, log_text, ap);
336  buf[size] = 0;
337  va_end(ap);
338 
339  // Get the current system time
340  timeval tv;
341  gettimeofday(&tv, nullptr);
342 
343  // Print the log entry
344  std::stringstream timeStr;
345  DATESTREAM
346  SPECIALLOG(buf)
347 
348  if (mLogFile.is_open())
349  {
350  timeStr << buf;
351  mThreadLocked = true;
352  mDelayedLog.push_back(timeStr.str());
353  mThreadLocked = false;
354  }
355 
356  if (mLogToStandardOut)
357  std::cout << timeStr.str() << buf << std::endl;
358 
359  // Delete temporary buffer
360  delete [] buf;
361 
362  SDL_mutexV(mMutex);
363 }
#define CAST_U32
Definition: cast.h:30
volatile bool mThreadLocked
Definition: logger.h:217
Settings settings
Definition: settings.cpp:31
bool mLogToStandardOut
Definition: logger.h:218
#define SPECIALLOG(x)
Definition: logger.cpp:73
std::vector< std::string > mDelayedLog
Definition: logger.h:215
bool disableLoggingInGame
Definition: settings.h:158
SDL_mutex * mMutex
Definition: logger.h:216
#define CAST_SIZE
Definition: cast.h:33
std::ofstream mLogFile
Definition: logger.h:214
#define DATESTREAM
Definition: logger.cpp:80

◆ safeError()

void Logger::safeError ( const std::string &  error_text)

Log an error and quit. The error will pop-up on Windows and Mac, and will be printed to standard error everywhere else.

Definition at line 378 of file logger.cpp.

References log(), and Actions::msg().

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), Setup_Video::apply(), ConfigManager::backupConfig(), TmwAthena::Network::dispatchMessages(), EAthena::Network::dispatchMessages(), Client::gameInit(), ModernOpenGLGraphics::postInit(), MobileOpenGL2Graphics::postInit(), setReportUnimplemented(), and GraphicsManager::setVideoMode().

379 {
380  log("Error: %s", error_text.c_str());
381 #ifdef USE_SDL2
382  SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
383  "Error",
384  error_text.c_str(),
385  nullptr);
386 #else // USE_SDL2
387 #ifdef WIN32
388  MessageBox(nullptr, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
389 #elif defined __APPLE__
390 // Str255 msg;
391 // CFStringRef error;
392 // error = CFStringCreateWithCString(nullptr,
393 // error_text.c_str(),
394 // kCFStringEncodingMacRoman);
395 // CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman);
396 // StandardAlert(kAlertStopAlert,
397 // (const unsigned char*)"\pError",
398 // (ConstStr255Param) msg, nullptr, nullptr);
399 #elif defined(__linux__) || defined(__linux)
400  std::cerr << "Error: " << error_text << std::endl;
401  const std::string msg = std::string("xmessage \"").append(
402  error_text).append("\"");
403  if (system(msg.c_str()) == -1)
404  std::cerr << "Error: " << error_text << std::endl;
405 #else // WIN32
406 
407  std::cerr << "Error: " << error_text << std::endl;
408 #endif // WIN32
409 #endif // USE_SDL2
410 
411  exit(1);
412 }
bool msg(InputEvent &event)
Definition: chat.cpp:38
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ setDebugLog()

void Logger::setDebugLog ( const bool  n)
inline

Definition at line 178 of file logger.h.

References mDebugLog.

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), Setup_Misc::apply(), and Client::gameInit().

179  { mDebugLog = n; }
bool mDebugLog
Definition: logger.h:219

◆ setLogFile()

void Logger::setLogFile ( const std::string &  logFilename)

Sets the file to log to and opens it

Definition at line 118 of file logger.cpp.

References mLogFile, and mLogToStandardOut.

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), Client::gameInit(), and TestMain::TestMain().

119 {
120  if (mLogFile.is_open())
121  mLogFile.close();
122 
123  mLogFile.open(logFilename.c_str(), std::ios_base::trunc);
124 
125  if (!mLogFile.is_open())
126  {
127  std::cout << "Warning: error while opening " << logFilename <<
128  " for writing.\n";
129  mLogToStandardOut = true;
130  }
131  else
132  {
133  mLogToStandardOut = false;
134  }
135 }
bool mLogToStandardOut
Definition: logger.h:218
std::ofstream mLogFile
Definition: logger.h:214

◆ setLogToStandardOut()

void Logger::setLogToStandardOut ( const bool  value)
inline

Sets whether the log should be written to standard output.

Definition at line 90 of file logger.h.

References EAthena::__attribute__, A_NONNULL, assertLog(), dlog(), dlog2(), flush(), gnu_printf, log(), log1(), log_r(), mLogToStandardOut, and ServerCommandType::str.

91  { mLogToStandardOut = value; }
bool mLogToStandardOut
Definition: logger.h:218

◆ setReportUnimplemented()

void Logger::setReportUnimplemented ( const bool  n)
inline

◆ unimplemented() [1/3]

void Logger::unimplemented ( const int  id)

Definition at line 451 of file logger.cpp.

References CAST_U32, DebugMessageListener::distributeEvent(), log(), mReportUnimplemented, ServerCommandType::str, and strprintf().

Referenced by setReportUnimplemented().

452 {
454  return;
455 
456  const std::string str = strprintf("Unimplimented packet: %d (0x%x)",
457  id,
458  CAST_U32(id));
460  log(str);
461 }
#define CAST_U32
Definition: cast.h:30
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
bool mReportUnimplemented
Definition: logger.h:220
static void distributeEvent(const std::string &msg)
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ unimplemented() [2/3]

void Logger::unimplemented ( const int  id,
const int  id2 
)

Definition at line 463 of file logger.cpp.

References CAST_U32, DebugMessageListener::distributeEvent(), log(), mReportUnimplemented, ServerCommandType::str, and strprintf().

465 {
467  return;
468 
469  const std::string str = strprintf(
470  "Unimplimented field value %d for packet %d (0x%x)",
471  id2,
472  id,
473  CAST_U32(id));
475  log(str);
476 }
#define CAST_U32
Definition: cast.h:30
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
bool mReportUnimplemented
Definition: logger.h:220
static void distributeEvent(const std::string &msg)
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ unimplemented() [3/3]

void Logger::unimplemented ( const uint32_t  id,
const uint32_t  id2,
const uint32_t  id3 
) const

Definition at line 478 of file logger.cpp.

References DebugMessageListener::distributeEvent(), mReportUnimplemented, ServerCommandType::str, and strprintf().

481 {
483  return;
484 
485  const std::string str = strprintf(
486  "Wrong actual or planned inbound packet size!. "
487  "Packet id: %u(0x%x), Planned size: %u, Actual size: %u",
488  id,
489  id,
490  id2,
491  id3);
493 }
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
bool mReportUnimplemented
Definition: logger.h:220
static void distributeEvent(const std::string &msg)

Field Documentation

◆ mDebugLog

bool Logger::mDebugLog
private

Definition at line 219 of file logger.h.

Referenced by dlog(), dlog2(), and setDebugLog().

◆ mDelayedLog

std::vector<std::string> Logger::mDelayedLog
private

Definition at line 215 of file logger.h.

Referenced by flush(), and log_r().

◆ mLogFile

std::ofstream Logger::mLogFile
private

Definition at line 214 of file logger.h.

Referenced by assertLog(), dlog(), dlog2(), flush(), log(), log1(), log_r(), setLogFile(), and ~Logger().

◆ mLogToStandardOut

bool Logger::mLogToStandardOut
private

Definition at line 218 of file logger.h.

Referenced by assertLog(), dlog(), dlog2(), log(), log1(), log_r(), setLogFile(), and setLogToStandardOut().

◆ mMutex

SDL_mutex* Logger::mMutex
private

Definition at line 216 of file logger.h.

Referenced by flush(), log_r(), and ~Logger().

◆ mReportUnimplemented

bool Logger::mReportUnimplemented
private

Definition at line 220 of file logger.h.

Referenced by setReportUnimplemented(), and unimplemented().

◆ mThreadLocked

volatile bool Logger::mThreadLocked
private

Definition at line 217 of file logger.h.

Referenced by flush(), and log_r().


The documentation for this class was generated from the following files: