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 68 of file logger.h.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( )

Constructor.

Definition at line 91 of file logger.cpp.

91  :
92  mLogFile(nullptr),
93  mDelayedLog(),
94  mMutex(SDL_CreateMutex()),
95  mThreadLocked(false),
96  mLogToStandardOut(true),
97  mDebugLog(false),
99 {
100 #if defined __native_client__ && defined(NACL_LOG)
101  std::cout.setf(std::ios_base::unitbuf);
102 #endif // defined __native_client__ && defined(NACL_LOG)
103 }
bool mLogToStandardOut
Definition: logger.h:223
bool mDebugLog
Definition: logger.h:224
SDL_mutex * mMutex
Definition: logger.h:221
bool mReportUnimplemented
Definition: logger.h:225
FILE * mLogFile
Definition: logger.h:219
volatile bool mThreadLocked
Definition: logger.h:222
std::vector< std::string > mDelayedLog
Definition: logger.h:220

◆ ~Logger()

Logger::~Logger ( )

Destructor, closes log file.

Definition at line 105 of file logger.cpp.

106 {
107  closeFile();
108  SDL_DestroyMutex(mMutex);
109 }
void closeFile()
Definition: logger.cpp:111

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

317 {
319  return;
320 
321  unsigned size = 1024;
322  if (strlen(log_text) * 3 > size)
323  size = CAST_U32(strlen(log_text) * 3);
324 
325  char* buf = new char[CAST_SIZE(size + 1)];
326  va_list ap;
327 
328  // Use a temporary buffer to fill in the variables
329  va_start(ap, log_text);
330  vsnprintf(buf, size, log_text, ap);
331  buf[size] = 0;
332  va_end(ap);
333 
334  // Get the current system time
335  timeval tv;
336  gettimeofday(&tv, nullptr);
337 
338  // Print the log entry
339  DATESTREAM
340  SPECIALLOG(buf)
341 
342  if (mLogFile != nullptr)
343  {
344  fprintf(mLogFile,
345  "%s %s\n",
346  timeStr.c_str(),
347  buf);
348  fflush(mLogFile);
349  }
350 
351  if (mLogToStandardOut)
352  {
353  fprintf(stdout,
354  "%s %s\n",
355  timeStr.c_str(),
356  buf);
357  }
358 
360 
361  // Delete temporary buffer
362  delete [] buf;
363 }
#define CAST_U32
Definition: cast.h:31
#define CAST_SIZE
Definition: cast.h:34
static void distributeEvent(const std::string &msg)
bool disableLoggingInGame
Definition: settings.h:161
#define SPECIALLOG(x)
Definition: logger.cpp:74
#define DATESTREAM
Definition: logger.cpp:81
int size()
Definition: emotedb.cpp:306
Settings settings
Definition: settings.cpp:32

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

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

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

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

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

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

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

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

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

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

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

Referenced by Gui::slowLogic().

◆ getFile()

FILE * Logger::getFile ( ) const

Definition at line 552 of file logger.cpp.

553 {
554  return mLogFile;
555 }

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

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

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(), EAthena::Network::dispatchMessages(), TmwAthena::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(), EAthena::GeneralHandler::GeneralHandler(), TmwAthena::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(), Resource::incRef(), SoundManager::info(), Joystick::init(), IPC::init(), SoundManager::init(), Perf::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(), OpenGLImageHelper::invalidate(), SafeOpenGLImageHelper::invalidate(), TestMain::invokeModernOpenGLRenderTest(), TestMain::invokeNormalOpenGLRenderTest(), TestMain::invokeSafeOpenGLRenderTest(), TestMain::invokeSoftwareRenderTest(), TestMain::invokeTest4(), itemTypeFromString(), CharDB::load(), Theme::load(), PoParser::load(), anonymous_namespace{musicloader.cpp}::ResourceLoader::load(), ImageHelper::load(), SafeOpenGLImageHelper::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(), loadXMLFile(), EffectManager::loadXmlFile(), SkillDialog::loadXmlFile(), AvatarDB::loadXmlFile(), ClanDb::loadXmlFile(), CommandsDB::loadXmlFile(), DeadDB::loadXmlFile(), ElementalDb::loadXmlFile(), EmoteDB::loadXmlFile(), GroupDb::loadXmlFile(), HomunculusDB::loadXmlFile(), HorseDB::loadXmlFile(), ItemFieldDb::loadXmlFile(), ItemOptionDb::loadXmlFile(), MercenaryDB::loadXmlFile(), ModDB::loadXmlFile(), MonsterDB::loadXmlFile(), NPCDB::loadXmlFile(), PETDB::loadXmlFile(), SkillUnitDb::loadXmlFile(), StatDb::loadXmlFile(), StatusEffectDB::loadXmlFile(), UnitsDb::loadXmlFile(), ItemDB::loadXmlFile(), Mutex::lock(), log(), GraphicsManager::logError(), EventsManager::logEvent(), ServerDialog::logic(), UpdaterWindow::logic(), Joystick::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(), ServerDialog::postInit(), MobileOpenGL2Graphics::postInit(), ModernOpenGLGraphics::postInit(), Theme::prepareThemePath(), Cpu::printFlags(), MemoryManager::printMemory(), Ea::BeingRecv::processBeingMove3(), EAthena::CashShopRecv::processCashShopSchedule(), EAthena::CashShopRecv::processCashShopTabPriceList(), EAthena::CharServerRecv::processCharCharacters(), EAthena::CharServerRecv::processCharLogin(), TmwAthena::CharServerRecv::processCharLogin(), EAthena::GeneralRecv::processConnectionProblem(), TmwAthena::GeneralRecv::processConnectionProblem(), EAthena::LoginRecv::processLoginData(), TmwAthena::LoginRecv::processLoginData(), Ea::LoginRecv::processLoginError(), EAthena::LoginRecv::processLoginError2(), EAthena::MailRecv::processMailList(), EAthena::GameRecv::processMapLogin(), TmwAthena::GameRecv::processMapLogin(), TmwAthena::InventoryRecv::processPlayerEquipment(), TmwAthena::InventoryRecv::processPlayerInventory(), TmwAthena::InventoryRecv::processPlayerStorage(), TmwAthena::InventoryRecv::processPlayerStorageEquip(), Ea::PlayerRecv::processPlayerWarp(), EAthena::MailRecv::processReadMail(), EAthena::LoginRecv::processServerVersion(), TmwAthena::LoginRecv::processServerVersion(), EAthena::SkillRecv::processSkillFailed(), TmwAthena::SkillRecv::processSkillFailed(), TmwAthena::TradeRecv::processTradeItemAddResponse(), Ea::LoginRecv::processUpdateHost(), EAthena::LoginRecv::processUpdateHost2(), MStack< T >::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(), 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(), Net::Download::start(), IPC::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(), 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 142 of file logger.cpp.

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

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

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

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(), AvatarDB::load(), BadgesDB::load(), CharDB::load(), ClanDb::load(), ColorDB::load(), CommandsDB::load(), DeadDB::load(), ElementalDb::load(), EmoteDB::load(), GroupDb::load(), HomunculusDB::load(), HorseDB::load(), ItemDB::load(), ItemFieldDb::load(), ItemOptionDb::load(), LanguageDb::load(), MapDB::load(), MercenaryDB::load(), ModDB::load(), MonsterDB::load(), NetworkDb::load(), NPCDB::load(), NpcDialogDB::load(), PaletteDB::load(), PETDB::load(), QuestDb::load(), SkillUnitDb::load(), SoundDB::load(), StatDb::load(), StatusEffectDB::load(), TextDb::load(), UnitsDb::load(), WeaponsDB::load(), loadHostsGroup(), UpdaterWindow::loadNews(), UpdaterWindow::loadPatch(), ServerDialog::loadServers(), EmoteDB::loadSpecialXmlFile(), LocalPlayer::LocalPlayer(), Joystick::open(), ParticleEmitter::ParticleEmitter(), Gui::postInit(), EAthena::GuildRecv::processGuildMemberList(), EAthena::GuildRecv::processGuildPosNameList(), EAthena::PartyRecv::processPartyInfo(), TmwAthena::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(), AvatarDB::unload(), BadgesDB::unload(), CharDB::unload(), ClanDb::unload(), ColorDB::unload(), CommandsDB::unload(), DeadDB::unload(), ElementalDb::unload(), EmoteDB::unload(), GroupDb::unload(), HomunculusDB::unload(), HorseDB::unload(), ItemDB::unload(), ItemFieldDb::unload(), ItemOptionDb::unload(), LanguageDb::unload(), MapDB::unload(), MercenaryDB::unload(), ModDB::unload(), MonsterDB::unload(), NetworkDb::unload(), NPCDB::unload(), NpcDialogDB::unload(), PaletteDB::unload(), PETDB::unload(), QuestDb::unload(), SkillUnitDb::unload(), SoundDB::unload(), StatDb::unload(), StatusEffectDB::unload(), TextDb::unload(), UnitsDb::unload(), WeaponsDB::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 365 of file logger.cpp.

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

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

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

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

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

◆ setDebugLog()

void Logger::setDebugLog ( const bool  n)
inline

Definition at line 181 of file logger.h.

182  { 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 120 of file logger.cpp.

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

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 91 of file logger.h.

92  { mLogToStandardOut = value; }

References mLogToStandardOut.

◆ setReportUnimplemented()

void Logger::setReportUnimplemented ( const bool  n)
inline

Definition at line 184 of file logger.h.

185  { mReportUnimplemented = n; }

References mReportUnimplemented.

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

◆ unimplemented() [1/3]

void Logger::unimplemented ( const int  id)

Definition at line 508 of file logger.cpp.

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

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

◆ unimplemented() [2/3]

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

Definition at line 520 of file logger.cpp.

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

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

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

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

Field Documentation

◆ mDebugLog

bool Logger::mDebugLog
private

Definition at line 224 of file logger.h.

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

◆ mDelayedLog

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

Definition at line 220 of file logger.h.

Referenced by flush(), and log_r().

◆ mLogFile

FILE* Logger::mLogFile
private

Definition at line 219 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 223 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 221 of file logger.h.

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

◆ mReportUnimplemented

bool Logger::mReportUnimplemented
private

Definition at line 225 of file logger.h.

Referenced by setReportUnimplemented(), and unimplemented().

◆ mThreadLocked

volatile bool Logger::mThreadLocked
private

Definition at line 222 of file logger.h.

Referenced by flush(), and log_r().


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