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 closeFile ()
 
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
 
FILE * getFile () const
 

Private Attributes

FILE * 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 90 of file logger.cpp.

90  :
91  mLogFile(nullptr),
92  mDelayedLog(),
93  mMutex(SDL_CreateMutex()),
94  mThreadLocked(false),
95  mLogToStandardOut(true),
96  mDebugLog(false),
98 {
99 #if defined __native_client__ && defined(NACL_LOG)
100  std::cout.setf(std::ios_base::unitbuf);
101 #endif // defined __native_client__ && defined(NACL_LOG)
102 }

◆ ~Logger()

Logger::~Logger ( )

Destructor, closes log file.

Definition at line 104 of file logger.cpp.

105 {
106  closeFile();
107  SDL_DestroyMutex(mMutex);
108 }

References closeFile(), and mMutex.

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 315 of file logger.cpp.

316 {
318  return;
319 
320  unsigned size = 1024;
321  if (strlen(log_text) * 3 > size)
322  size = CAST_U32(strlen(log_text) * 3);
323 
324  char* buf = new char[CAST_SIZE(size + 1)];
325  va_list ap;
326 
327  // Use a temporary buffer to fill in the variables
328  va_start(ap, log_text);
329  vsnprintf(buf, size, log_text, ap);
330  buf[size] = 0;
331  va_end(ap);
332 
333  // Get the current system time
334  timeval tv;
335  gettimeofday(&tv, nullptr);
336 
337  // Print the log entry
338  DATESTREAM
339  SPECIALLOG(buf)
340 
341  if (mLogFile != nullptr)
342  {
343  fprintf(mLogFile,
344  "%s %s\n",
345  timeStr.c_str(),
346  buf);
347  fflush(mLogFile);
348  }
349 
350  if (mLogToStandardOut)
351  {
352  fprintf(stdout,
353  "%s %s\n",
354  timeStr.c_str(),
355  buf);
356  }
357 
359 
360  // Delete temporary buffer
361  delete [] buf;
362 }

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

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

◆ closeFile()

void Logger::closeFile ( )

Definition at line 110 of file logger.cpp.

111 {
112  if (mLogFile != nullptr)
113  {
114  fclose(mLogFile);
115  mLogFile = nullptr;
116  }
117 }

References mLogFile.

Referenced by setLogFile(), and ~Logger().

◆ dlog()

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

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

Definition at line 147 of file logger.cpp.

148 {
149  if (!mDebugLog)
150  return;
151 
152  // Get the current system time
153  timeval tv;
154  gettimeofday(&tv, nullptr);
155 
156  // Print the log entry
157  DATESTREAM
158  DSPECIALLOG(str.c_str())
159 
160  if (mLogFile != nullptr)
161  {
162  fprintf(mLogFile,
163  "%s %s\n",
164  timeStr.c_str(),
165  str.c_str());
166  }
167 
168  if (mLogToStandardOut)
169  {
170  fprintf(stdout,
171  "%s %s\n",
172  timeStr.c_str(),
173  str.c_str());
174  }
175 }

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

Referenced by LocalPlayer::fixPos(), and Net::MessageIn::readBytes().

◆ dlog2()

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

Definition at line 177 of file logger.cpp.

180 {
181  if (!mDebugLog)
182  return;
183 
184  // Get the current system time
185  timeval tv;
186  gettimeofday(&tv, nullptr);
187 
188  // Print the log entry
189  DATESTREAM
190  DSPECIALLOG(str.c_str())
191 
192  if (mLogFile != nullptr)
193  {
194  if (comment != nullptr)
195  {
196  fprintf(mLogFile,
197  "%s %04d %s: %s\n",
198  timeStr.c_str(),
199  pos,
200  str.c_str(),
201  comment);
202  }
203  else
204  {
205  fprintf(mLogFile,
206  "%s %04d %s\n",
207  timeStr.c_str(),
208  pos,
209  str.c_str());
210  }
211  fflush(mLogFile);
212  }
213 
214  if (mLogToStandardOut)
215  {
216  if (comment != nullptr)
217  {
218  fprintf(stdout,
219  "%s %04d %s: %s\n",
220  timeStr.c_str(),
221  pos,
222  str.c_str(),
223  comment);
224  }
225  else
226  {
227  fprintf(stdout,
228  "%s %04d %s\n",
229  timeStr.c_str(),
230  pos,
231  str.c_str());
232  }
233  }
234 }

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

◆ 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 471 of file logger.cpp.

472 {
473  log("Error: %s", error_text.c_str());
474 #ifdef USE_SDL2
475  SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
476  "Error",
477  error_text.c_str(),
478  nullptr);
479 #else // USE_SDL2
480 #ifdef WIN32
481  MessageBox(nullptr, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
482 #elif defined __APPLE__
483 // Str255 msg;
484 // CFStringRef error;
485 // error = CFStringCreateWithCString(nullptr,
486 // error_text.c_str(),
487 // kCFStringEncodingMacRoman);
488 // CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman);
489 // StandardAlert(kAlertStopAlert,
490 // (const unsigned char*)"\pError",
491 // (ConstStr255Param) msg, nullptr, nullptr);
492 #elif defined(__linux__) || defined(__linux)
493  std::cerr << "Error: " << error_text << std::endl;
494  const std::string msg("xmessage \"Error happened. "
495  "Please see log file for more information.\"");
496  if (system(msg.c_str()) == -1)
497  std::cerr << "Error: " << error_text << std::endl;
498 #else // WIN32
499 
500  std::cerr << "Error: " << error_text << std::endl;
501 #endif // WIN32
502 #endif // USE_SDL2
503 
504  exit(1);
505 }

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

Referenced by Font::Font(), Client::gameInit(), Dirs::initConfigDir(), Dirs::initLocalDataDir(), ConfigManager::initServerConfig(), Dirs::initTempDir(), Dirs::initUsersDir(), ModernOpenGLGraphics::postInit(), and GraphicsManager::setVideoMode().

◆ flush()

void Logger::flush ( )

Definition at line 417 of file logger.cpp.

418 {
419  if (!mThreadLocked)
420  {
421  SDL_mutexP(mMutex);
422  FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, mDelayedLog)
423  {
424  fputs((*it).c_str(), mLogFile);
425  fputs("\n", mLogFile);
426  }
427  fflush(mLogFile);
428  mDelayedLog.clear();
429  SDL_mutexV(mMutex);
430  }
431 }

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

Referenced by Gui::slowLogic().

◆ getFile()

FILE * Logger::getFile ( ) const

Definition at line 551 of file logger.cpp.

552 {
553  return mLogFile;
554 }

References mLogFile.

Referenced by Net::Download::addCommonFlags().

◆ 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 268 of file logger.cpp.

269 {
271  return;
272 
273  unsigned size = 1024;
274  if (strlen(log_text) * 3 > size)
275  size = CAST_U32(strlen(log_text) * 3);
276 
277  char* buf = new char[CAST_SIZE(size + 1)];
278  va_list ap;
279 
280  // Use a temporary buffer to fill in the variables
281  va_start(ap, log_text);
282  vsnprintf(buf, size, log_text, ap);
283  buf[size] = 0;
284  va_end(ap);
285 
286  // Get the current system time
287  timeval tv;
288  gettimeofday(&tv, nullptr);
289 
290  // Print the log entry
291  DATESTREAM
292  SPECIALLOG(buf)
293 
294  if (mLogFile != nullptr)
295  {
296  fprintf(mLogFile,
297  "%s %s\n",
298  timeStr.c_str(),
299  buf);
300  fflush(mLogFile);
301  }
302 
303  if (mLogToStandardOut)
304  {
305  fprintf(stdout,
306  "%s %s\n",
307  timeStr.c_str(),
308  buf);
309  }
310 
311  // Delete temporary buffer
312  delete [] buf;
313 }

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

Referenced by ChangeEmailDialog::action(), ChangePasswordDialog::action(), RegisterDialog::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(), 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(), debugCallback(), Resource::decRef(), ResourceManager::deleteInstance(), ResourceManager::deleteResourceManager(), destroyGuiWindows(), Cpu::detect(), GraphicsManager::detectGraphics(), GraphicsManager::detectPixelSize(), TmwAthena::Network::dispatchMessages(), EAthena::Network::dispatchMessages(), Font::doClean(), ServerDialog::downloadUpdate(), dumpLibs(), dumpLinkedSdlVersion(), 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(), TmwAthena::GeneralHandler::GeneralHandler(), EAthena::GeneralHandler::GeneralHandler(), ImageSet::get(), ResourceManager::get(), SpriteDef::getAction(), SDL::getAllVideoModes(), Theme::getColor(), UserPalette::getColor(), ScrollArea::getImageByState(), Theme::getProgressColor(), SafeOpenGLImageHelper::glLoad(), PIS_dotdotdot::ignore(), PIS_blinkname::ignore(), Image::Image(), Resource::incRef(), SoundManager::info(), Perf::init(), IPC::init(), SoundManager::init(), Joystick::init(), Configuration::init(), EggSelectionDialog::initButtons(), Dirs::initConfigDir(), ConfigManager::initConfiguration(), initDefaultThemePath(), GraphicsManager::initGraphics(), GettextHelper::initLang(), Dirs::initRootDir(), Dirs::initScreenshotDir(), ConfigManager::initServerConfig(), Client::initSoundManager(), 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(), ServerDialog::loadServers(), VirtFs::loadTextFile(), VirtFs::loadTextFileString(), loadTxtFile(), loadUnit(), UpdaterWindow::loadUpdates(), ItemFieldDb::loadXmlFile(), DeadDB::loadXmlFile(), StatDb::loadXmlFile(), SkillUnitDb::loadXmlFile(), PETDB::loadXmlFile(), ModDB::loadXmlFile(), GroupDb::loadXmlFile(), ItemOptionDb::loadXmlFile(), UnitsDb::loadXmlFile(), AvatarDB::loadXmlFile(), ClanDb::loadXmlFile(), HorseDB::loadXmlFile(), ElementalDb::loadXmlFile(), HomunculusDB::loadXmlFile(), CommandsDB::loadXmlFile(), MercenaryDB::loadXmlFile(), MonsterDB::loadXmlFile(), EmoteDB::loadXmlFile(), ItemDB::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(), EAthena::GeneralRecv::processConnectionProblem(), TmwAthena::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(), TmwAthena::SkillRecv::processSkillFailed(), EAthena::SkillRecv::processSkillFailed(), TmwAthena::TradeRecv::processTradeItemAddResponse(), Ea::LoginRecv::processUpdateHost(), EAthena::LoginRecv::processUpdateHost2(), MStack< ClipRect >::push(), VirtFs::ZipReader::readArchiveInfo(), MapDB::readAtlas(), 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::removeOldKeys(), safeError(), Map::saveExtraLayer(), Game::saveScreenshot(), Perf::selectWorstFrame(), Being::setAction(), Image::setAlpha(), Desktop::setBestFittingWallpaper(), setBrandingDefaults(), CharSelectDialog::setCharacter(), setConfigDefaults(), setConfigDefaults2(), setEnv(), setFeaturesDefaults(), GraphicsManager::setGLVersion(), WindowManager::setIcon(), ComplexInventory::setItem(), Graphics::setMainFlags(), Graphics::setOpenGLMode(), setPathsDefaults(), Graphics::setScale(), NpcDialog::setSkin(), BeingInfo::setTargetCursorSize(), Gui::setUseCustomCursor(), GraphicsManager::setVideoMode(), IPC::start(), Net::Download::start(), 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().

◆ log() [2/2]

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

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

Definition at line 141 of file logger.cpp.

142 {
143  log("%s", str.c_str());
144 }

References log().

◆ log1()

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

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

Definition at line 237 of file logger.cpp.

238 {
240  return;
241 
242  // Get the current system time
243  timeval tv;
244  gettimeofday(&tv, nullptr);
245 
246  // Print the log entry
247  DATESTREAM
248  SPECIALLOG(buf)
249 
250  if (mLogFile != nullptr)
251  {
252  fprintf(mLogFile,
253  "%s %s\n",
254  timeStr.c_str(),
255  buf);
256  fflush(mLogFile);
257  }
258 
259  if (mLogToStandardOut)
260  {
261  fprintf(stdout,
262  "%s %s\n",
263  timeStr.c_str(),
264  buf);
265  }
266 }

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

Referenced by ConnectionDialog::action(), Map::addExtraLayer(), LayoutArray::align(), ResourceManager::clearDeleted(), SoundManager::close(), Ea::Network::connect(), MapReader::createEmptyMap(), GraphicsManager::createTextureSampler(), ResourceManager::deleteInstance(), GraphicsManager::detectGraphics(), EffectManager::EffectManager(), Client::gameClear(), Client::gameExec(), Client::gameInit(), SDL::getAllVideoModes(), EventsManager::handleCommonEvents(), EventsManager::handleEvents(), SoundManager::info(), SoundManager::init(), Configuration::init(), ConfigManager::initConfiguration(), GraphicsManager::initOpenGLFunctions(), Dirs::initUpdatesDir(), ItemFieldDb::load(), LanguageDb::load(), PaletteDB::load(), SoundDB::load(), TextDb::load(), WeaponsDB::load(), ModDB::load(), BadgesDB::load(), StatDb::load(), DeadDB::load(), GroupDb::load(), ItemOptionDb::load(), AvatarDB::load(), PETDB::load(), SkillUnitDb::load(), UnitsDb::load(), QuestDb::load(), CharDB::load(), ClanDb::load(), HomunculusDB::load(), MercenaryDB::load(), MonsterDB::load(), NPCDB::load(), CommandsDB::load(), ElementalDb::load(), HorseDB::load(), ItemDB::load(), MapDB::load(), NetworkDb::load(), NpcDialogDB::load(), ColorDB::load(), EmoteDB::load(), StatusEffectDB::load(), loadHostsGroup(), UpdaterWindow::loadNews(), UpdaterWindow::loadPatch(), 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(), Graphics::setOpenGLMode(), ParticleEngine::setupEngine(), Net::Download::start(), ConfigManager::storeSafeParameters(), PaletteDB::unload(), ItemFieldDb::unload(), WeaponsDB::unload(), BadgesDB::unload(), ModDB::unload(), StatDb::unload(), LanguageDb::unload(), SoundDB::unload(), GroupDb::unload(), ItemOptionDb::unload(), AvatarDB::unload(), UnitsDb::unload(), ClanDb::unload(), TextDb::unload(), MonsterDB::unload(), CommandsDB::unload(), PETDB::unload(), MercenaryDB::unload(), SkillUnitDb::unload(), HomunculusDB::unload(), NPCDB::unload(), ElementalDb::unload(), ItemDB::unload(), QuestDb::unload(), CharDB::unload(), DeadDB::unload(), HorseDB::unload(), NetworkDb::unload(), NpcDialogDB::unload(), EmoteDB::unload(), MapDB::unload(), StatusEffectDB::unload(), ColorDB::unload(), GraphicsManager::updateDebugLog(), GraphicsManager::updateExtensions(), GraphicsManager::updatePlanformExtensions(), GraphicsManager::updateTextureCompressionFormat(), GraphicsManager::updateTextureFormat(), Graphics::videoInfo(), Configuration::write(), ItemShortcut::~ItemShortcut(), and LocalPlayer::~LocalPlayer().

◆ log_r()

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

Enters a message in the log (thread safe).

Definition at line 364 of file logger.cpp.

365 {
367  return;
368 
369  SDL_mutexP(mMutex);
370 
371  unsigned size = 1024;
372  if (strlen(log_text) * 3 > size)
373  size = CAST_U32(strlen(log_text) * 3);
374 
375  char* buf = new char[CAST_SIZE(size + 1)];
376  va_list ap;
377 
378  // Use a temporary buffer to fill in the variables
379  va_start(ap, log_text);
380  vsnprintf(buf, size, log_text, ap);
381  buf[size] = 0;
382  va_end(ap);
383 
384  // Get the current system time
385  timeval tv;
386  gettimeofday(&tv, nullptr);
387 
388  // Print the log entry
389  DATESTREAM
390  SPECIALLOG(buf)
391 
392  if (mLogFile != nullptr)
393  {
394  std::string tmpStr = strprintf(
395  "%s %s\n",
396  timeStr.c_str(),
397  buf);
398  mThreadLocked = true;
399  mDelayedLog.push_back(tmpStr);
400  mThreadLocked = false;
401  }
402 
403  if (mLogToStandardOut)
404  {
405  fprintf(stdout,
406  "%s %s\n",
407  timeStr.c_str(),
408  buf);
409  }
410 
411  // Delete temporary buffer
412  delete [] buf;
413 
414  SDL_mutexV(mMutex);
415 }

References CAST_SIZE, CAST_U32, DATESTREAM, Settings::disableLoggingInGame, mDelayedLog, mLogFile, mLogToStandardOut, mMutex, mThreadLocked, settings, EmoteDB::size(), SPECIALLOG, and strprintf().

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

◆ 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 434 of file logger.cpp.

435 {
436  log("Error: %s", error_text.c_str());
437 #ifdef USE_SDL2
438  SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
439  "Error",
440  error_text.c_str(),
441  nullptr);
442 #else // USE_SDL2
443 #ifdef WIN32
444  MessageBox(nullptr, error_text.c_str(), "Error", MB_ICONERROR | MB_OK);
445 #elif defined __APPLE__
446 // Str255 msg;
447 // CFStringRef error;
448 // error = CFStringCreateWithCString(nullptr,
449 // error_text.c_str(),
450 // kCFStringEncodingMacRoman);
451 // CFStringGetPascalString(error, msg, 255, kCFStringEncodingMacRoman);
452 // StandardAlert(kAlertStopAlert,
453 // (const unsigned char*)"\pError",
454 // (ConstStr255Param) msg, nullptr, nullptr);
455 #elif defined(__linux__) || defined(__linux)
456  std::cerr << "Error: " << error_text << std::endl;
457  const std::string msg = std::string("xmessage \"").append(
458  error_text).append("\"");
459  if (system(msg.c_str()) == -1)
460  std::cerr << "Error: " << error_text << std::endl;
461 #else // WIN32
462 
463  std::cerr << "Error: " << error_text << std::endl;
464 #endif // WIN32
465 #endif // USE_SDL2
466 
467  exit(1);
468 }

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

Referenced by Setup_Video::apply(), ConfigManager::backupConfig(), TmwAthena::Network::dispatchMessages(), EAthena::Network::dispatchMessages(), Client::gameInit(), MobileOpenGL2Graphics::postInit(), ModernOpenGLGraphics::postInit(), and GraphicsManager::setVideoMode().

◆ setDebugLog()

void Logger::setDebugLog ( const bool  n)
inline

Definition at line 180 of file logger.h.

181  { mDebugLog = n; }

References mDebugLog.

Referenced by Setup_Misc::apply(), and Client::gameInit().

◆ setLogFile()

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

Sets the file to log to and opens it

Definition at line 119 of file logger.cpp.

120 {
121  closeFile();
122 
123 #ifdef __SWITCH__
124  mLogFile = nullptr;
125 #else
126  mLogFile = fopen(logFilename.c_str(), "wt");
127 #endif
128 
129  if (mLogFile == nullptr)
130  {
131  std::cout << "Warning: error while opening " << logFilename <<
132  " for writing.\n";
133  mLogToStandardOut = true;
134  }
135  else
136  {
137  mLogToStandardOut = false;
138  }
139 }

References closeFile(), mLogFile, and mLogToStandardOut.

Referenced by Client::gameInit(), and TestMain::TestMain().

◆ 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.

91  { mLogToStandardOut = value; }

References mLogToStandardOut.

◆ setReportUnimplemented()

void Logger::setReportUnimplemented ( const bool  n)
inline

Definition at line 183 of file logger.h.

184  { mReportUnimplemented = n; }

References mReportUnimplemented.

Referenced by Setup_Misc::apply(), and Client::gameInit().

◆ unimplemented() [1/3]

void Logger::unimplemented ( const int  id)

Definition at line 507 of file logger.cpp.

508 {
510  return;
511 
512  const std::string str = strprintf("Unimplimented packet: %d (0x%x)",
513  id,
514  CAST_U32(id));
516  log(str);
517 }

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

◆ unimplemented() [2/3]

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

Definition at line 519 of file logger.cpp.

521 {
523  return;
524 
525  const std::string str = strprintf(
526  "Unimplimented field value %d for packet %d (0x%x)",
527  id2,
528  id,
529  CAST_U32(id));
531  log(str);
532 }

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

◆ unimplemented() [3/3]

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

Definition at line 534 of file logger.cpp.

537 {
539  return;
540 
541  const std::string str = strprintf(
542  "Wrong actual or planned inbound packet size!. "
543  "Packet id: %u(0x%x), Planned size: %u, Actual size: %u",
544  id,
545  id,
546  id2,
547  id3);
549 }

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

Field Documentation

◆ mDebugLog

bool Logger::mDebugLog
private

Definition at line 223 of file logger.h.

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

◆ mDelayedLog

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

Definition at line 219 of file logger.h.

Referenced by flush(), and log_r().

◆ mLogFile

FILE* Logger::mLogFile
private

Definition at line 218 of file logger.h.

Referenced by assertLog(), closeFile(), dlog(), dlog2(), flush(), getFile(), log(), log1(), log_r(), and setLogFile().

◆ mLogToStandardOut

bool Logger::mLogToStandardOut
private

Definition at line 222 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 220 of file logger.h.

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

◆ mReportUnimplemented

bool Logger::mReportUnimplemented
private

Definition at line 224 of file logger.h.

Referenced by setReportUnimplemented(), and unimplemented().

◆ mThreadLocked

volatile bool Logger::mThreadLocked
private

Definition at line 221 of file logger.h.

Referenced by flush(), and log_r().


The documentation for this class was generated from the following files:
DATESTREAM
#define DATESTREAM
Definition: logger.cpp:80
Logger::closeFile
void closeFile()
Definition: logger.cpp:110
CAST_SIZE
#define CAST_SIZE
Definition: cast.h:33
DebugMessageListener::distributeEvent
static void distributeEvent(const std::string &msg)
Definition: debugmessagelistener.cpp:29
settings
Settings settings
Definition: settings.cpp:31
Actions::msg
bool msg(InputEvent &event)
Definition: chat.cpp:38
Logger::mDelayedLog
std::vector< std::string > mDelayedLog
Definition: logger.h:219
CAST_U32
#define CAST_U32
Definition: cast.h:30
Logger::mLogToStandardOut
bool mLogToStandardOut
Definition: logger.h:222
if
if(!vert) return
Logger::mThreadLocked
volatile bool mThreadLocked
Definition: logger.h:221
strprintf
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
Logger::mDebugLog
bool mDebugLog
Definition: logger.h:223
SPECIALLOG
#define SPECIALLOG(x)
Definition: logger.cpp:73
EmoteDB::size
int size()
Definition: emotedb.cpp:305
Settings::disableLoggingInGame
bool disableLoggingInGame
Definition: settings.h:160
Logger::mMutex
SDL_mutex * mMutex
Definition: logger.h:220
Logger::mReportUnimplemented
bool mReportUnimplemented
Definition: logger.h:224
DSPECIALLOG
#define DSPECIALLOG(x)
Definition: logger.cpp:74
Logger::mLogFile
FILE * mLogFile
Definition: logger.h:218
Logger::log
void log(const char *const log_text,...)
Definition: logger.cpp:268
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24