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
 

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 }
volatile bool mThreadLocked
Definition: logger.h:219
FILE * mLogFile
Definition: logger.h:216
bool mLogToStandardOut
Definition: logger.h:220
std::vector< std::string > mDelayedLog
Definition: logger.h:217
SDL_mutex * mMutex
Definition: logger.h:218
bool mReportUnimplemented
Definition: logger.h:222
bool mDebugLog
Definition: logger.h:221

◆ ~Logger()

Logger::~Logger ( )

Destructor, closes log file.

Definition at line 104 of file logger.cpp.

References closeFile(), and mMutex.

105 {
106  closeFile();
107  SDL_DestroyMutex(mMutex);
108 }
void closeFile()
Definition: logger.cpp:110
SDL_mutex * mMutex
Definition: logger.h:218

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 311 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(), EventsManager::logEvent(), VirtFs::FsDir::rwops_seek(), VirtFs::FsZip::rwops_seek(), setLogToStandardOut(), and WhoIsOnline::slowLogic().

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

◆ closeFile()

void Logger::closeFile ( )

Definition at line 110 of file logger.cpp.

References mLogFile.

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

111 {
112  if (mLogFile != nullptr)
113  {
114  fclose(mLogFile);
115  mLogFile = nullptr;
116  }
117 }
FILE * mLogFile
Definition: logger.h:216

◆ 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  DATESTREAM
154  DSPECIALLOG(str.c_str())
155 
156  if (mLogFile != nullptr)
157  {
158  fprintf(mLogFile,
159  "%s %s\n",
160  timeStr.c_str(),
161  str.c_str());
162  }
163 
164  if (mLogToStandardOut)
165  {
166  fprintf(stdout,
167  "%s %s\n",
168  timeStr.c_str(),
169  str.c_str());
170  }
171 }
FILE * mLogFile
Definition: logger.h:216
bool mLogToStandardOut
Definition: logger.h:220
bool mDebugLog
Definition: logger.h:221
#define DSPECIALLOG(x)
Definition: logger.cpp:74
#define DATESTREAM
Definition: logger.cpp:80

◆ dlog2()

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

Definition at line 173 of file logger.cpp.

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

Referenced by setLogToStandardOut().

176 {
177  if (!mDebugLog)
178  return;
179 
180  // Get the current system time
181  timeval tv;
182  gettimeofday(&tv, nullptr);
183 
184  // Print the log entry
185  DATESTREAM
186  DSPECIALLOG(str.c_str())
187 
188  if (mLogFile != nullptr)
189  {
190  if (comment != nullptr)
191  {
192  fprintf(mLogFile,
193  "%s %04d %s: %s\n",
194  timeStr.c_str(),
195  pos,
196  str.c_str(),
197  comment);
198  }
199  else
200  {
201  fprintf(mLogFile,
202  "%s %04d %s\n",
203  timeStr.c_str(),
204  pos,
205  str.c_str());
206  }
207  fflush(mLogFile);
208  }
209 
210  if (mLogToStandardOut)
211  {
212  if (comment != nullptr)
213  {
214  fprintf(stdout,
215  "%s %04d %s: %s\n",
216  timeStr.c_str(),
217  pos,
218  str.c_str(),
219  comment);
220  }
221  else
222  {
223  fprintf(stdout,
224  "%s %04d %s\n",
225  timeStr.c_str(),
226  pos,
227  str.c_str());
228  }
229  }
230 }
FILE * mLogFile
Definition: logger.h:216
bool mLogToStandardOut
Definition: logger.h:220
bool mDebugLog
Definition: logger.h:221
#define DSPECIALLOG(x)
Definition: logger.cpp:74
#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 467 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().

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

◆ flush()

void Logger::flush ( )

Definition at line 413 of file logger.cpp.

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

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

414 {
415  if (!mThreadLocked)
416  {
417  SDL_mutexP(mMutex);
418  FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, mDelayedLog)
419  {
420  fputs((*it).c_str(), mLogFile);
421  fputs("\n", mLogFile);
422  }
423  fflush(mLogFile);
424  mDelayedLog.clear();
425  SDL_mutexV(mMutex);
426  }
427 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
volatile bool mThreadLocked
Definition: logger.h:219
FILE * mLogFile
Definition: logger.h:216
std::vector< std::string > mDelayedLog
Definition: logger.h:217
SDL_mutex * mMutex
Definition: logger.h:218

◆ 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 264 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(), OpenGLImageHelper::invalidate(), SafeOpenGLImageHelper::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(), ItemFieldDb::loadXmlFile(), DeadDB::loadXmlFile(), StatDb::loadXmlFile(), GroupDb::loadXmlFile(), PETDB::loadXmlFile(), SkillUnitDb::loadXmlFile(), ModDB::loadXmlFile(), ItemOptionDb::loadXmlFile(), UnitsDb::loadXmlFile(), AvatarDB::loadXmlFile(), ClanDb::loadXmlFile(), HorseDB::loadXmlFile(), CommandsDB::loadXmlFile(), ElementalDb::loadXmlFile(), HomunculusDB::loadXmlFile(), MonsterDB::loadXmlFile(), MercenaryDB::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(), 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::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(), 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().

265 {
267  return;
268 
269  unsigned size = 1024;
270  if (strlen(log_text) * 3 > size)
271  size = CAST_U32(strlen(log_text) * 3);
272 
273  char* buf = new char[CAST_SIZE(size + 1)];
274  va_list ap;
275 
276  // Use a temporary buffer to fill in the variables
277  va_start(ap, log_text);
278  vsnprintf(buf, size, log_text, ap);
279  buf[size] = 0;
280  va_end(ap);
281 
282  // Get the current system time
283  timeval tv;
284  gettimeofday(&tv, nullptr);
285 
286  // Print the log entry
287  DATESTREAM
288  SPECIALLOG(buf)
289 
290  if (mLogFile != nullptr)
291  {
292  fprintf(mLogFile,
293  "%s %s\n",
294  timeStr.c_str(),
295  buf);
296  fflush(mLogFile);
297  }
298 
299  if (mLogToStandardOut)
300  {
301  fprintf(stdout,
302  "%s %s\n",
303  timeStr.c_str(),
304  buf);
305  }
306 
307  // Delete temporary buffer
308  delete [] buf;
309 }
#define CAST_U32
Definition: cast.h:30
FILE * mLogFile
Definition: logger.h:216
Settings settings
Definition: settings.cpp:31
bool mLogToStandardOut
Definition: logger.h:220
#define SPECIALLOG(x)
Definition: logger.cpp:73
bool disableLoggingInGame
Definition: settings.h:157
#define CAST_SIZE
Definition: cast.h:33
#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:264

◆ log1()

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

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

Definition at line 233 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(), ItemFieldDb::load(), LanguageDb::load(), PaletteDB::load(), SoundDB::load(), TextDb::load(), WeaponsDB::load(), ModDB::load(), BadgesDB::load(), StatDb::load(), GroupDb::load(), DeadDB::load(), ItemOptionDb::load(), PETDB::load(), SkillUnitDb::load(), AvatarDB::load(), UnitsDb::load(), QuestDb::load(), CharDB::load(), ClanDb::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(), ItemFieldDb::unload(), WeaponsDB::unload(), ModDB::unload(), BadgesDB::unload(), StatDb::unload(), SoundDB::unload(), GroupDb::unload(), LanguageDb::unload(), UnitsDb::unload(), ItemOptionDb::unload(), AvatarDB::unload(), TextDb::unload(), ClanDb::unload(), NPCDB::unload(), PETDB::unload(), SkillUnitDb::unload(), MonsterDB::unload(), HomunculusDB::unload(), MercenaryDB::unload(), CommandsDB::unload(), ElementalDb::unload(), ItemDB::unload(), CharDB::unload(), QuestDb::unload(), DeadDB::unload(), NetworkDb::unload(), HorseDB::unload(), NpcDialogDB::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().

234 {
236  return;
237 
238  // Get the current system time
239  timeval tv;
240  gettimeofday(&tv, nullptr);
241 
242  // Print the log entry
243  DATESTREAM
244  SPECIALLOG(buf)
245 
246  if (mLogFile != nullptr)
247  {
248  fprintf(mLogFile,
249  "%s %s\n",
250  timeStr.c_str(),
251  buf);
252  fflush(mLogFile);
253  }
254 
255  if (mLogToStandardOut)
256  {
257  fprintf(stdout,
258  "%s %s\n",
259  timeStr.c_str(),
260  buf);
261  }
262 }
FILE * mLogFile
Definition: logger.h:216
Settings settings
Definition: settings.cpp:31
bool mLogToStandardOut
Definition: logger.h:220
#define SPECIALLOG(x)
Definition: logger.cpp:73
bool disableLoggingInGame
Definition: settings.h:157
#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 360 of file logger.cpp.

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

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

361 {
363  return;
364 
365  SDL_mutexP(mMutex);
366 
367  unsigned size = 1024;
368  if (strlen(log_text) * 3 > size)
369  size = CAST_U32(strlen(log_text) * 3);
370 
371  char* buf = new char[CAST_SIZE(size + 1)];
372  va_list ap;
373 
374  // Use a temporary buffer to fill in the variables
375  va_start(ap, log_text);
376  vsnprintf(buf, size, log_text, ap);
377  buf[size] = 0;
378  va_end(ap);
379 
380  // Get the current system time
381  timeval tv;
382  gettimeofday(&tv, nullptr);
383 
384  // Print the log entry
385  DATESTREAM
386  SPECIALLOG(buf)
387 
388  if (mLogFile != nullptr)
389  {
390  std::string tmpStr = strprintf(
391  "%s %s\n",
392  timeStr.c_str(),
393  buf);
394  mThreadLocked = true;
395  mDelayedLog.push_back(tmpStr);
396  mThreadLocked = false;
397  }
398 
399  if (mLogToStandardOut)
400  {
401  fprintf(stdout,
402  "%s %s\n",
403  timeStr.c_str(),
404  buf);
405  }
406 
407  // Delete temporary buffer
408  delete [] buf;
409 
410  SDL_mutexV(mMutex);
411 }
#define CAST_U32
Definition: cast.h:30
volatile bool mThreadLocked
Definition: logger.h:219
FILE * mLogFile
Definition: logger.h:216
Settings settings
Definition: settings.cpp:31
bool mLogToStandardOut
Definition: logger.h:220
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
#define SPECIALLOG(x)
Definition: logger.cpp:73
std::vector< std::string > mDelayedLog
Definition: logger.h:217
bool disableLoggingInGame
Definition: settings.h:157
SDL_mutex * mMutex
Definition: logger.h:218
#define CAST_SIZE
Definition: cast.h:33
#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 430 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().

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

◆ setDebugLog()

void Logger::setDebugLog ( const bool  n)
inline

Definition at line 180 of file logger.h.

References mDebugLog.

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

181  { mDebugLog = n; }
bool mDebugLog
Definition: logger.h:221

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

References closeFile(), mLogFile, and mLogToStandardOut.

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

120 {
121  closeFile();
122 
123  mLogFile = fopen(logFilename.c_str(), "wt");
124 
125  if (mLogFile == nullptr)
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 }
FILE * mLogFile
Definition: logger.h:216
bool mLogToStandardOut
Definition: logger.h:220
void closeFile()
Definition: logger.cpp:110

◆ 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(), closeFile(), dlog(), dlog2(), flush(), gnu_printf, log(), log1(), log_r(), mLogToStandardOut, and ServerCommandType::str.

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

◆ setReportUnimplemented()

void Logger::setReportUnimplemented ( const bool  n)
inline

◆ unimplemented() [1/3]

void Logger::unimplemented ( const int  id)

Definition at line 503 of file logger.cpp.

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

Referenced by setReportUnimplemented().

504 {
506  return;
507 
508  const std::string str = strprintf("Unimplimented packet: %d (0x%x)",
509  id,
510  CAST_U32(id));
512  log(str);
513 }
#define CAST_U32
Definition: cast.h:30
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
bool mReportUnimplemented
Definition: logger.h:222
static void distributeEvent(const std::string &msg)
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ unimplemented() [2/3]

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

Definition at line 515 of file logger.cpp.

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

517 {
519  return;
520 
521  const std::string str = strprintf(
522  "Unimplimented field value %d for packet %d (0x%x)",
523  id2,
524  id,
525  CAST_U32(id));
527  log(str);
528 }
#define CAST_U32
Definition: cast.h:30
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
bool mReportUnimplemented
Definition: logger.h:222
static void distributeEvent(const std::string &msg)
void log(const char *const log_text,...)
Definition: logger.cpp:264

◆ unimplemented() [3/3]

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

Definition at line 530 of file logger.cpp.

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

533 {
535  return;
536 
537  const std::string str = strprintf(
538  "Wrong actual or planned inbound packet size!. "
539  "Packet id: %u(0x%x), Planned size: %u, Actual size: %u",
540  id,
541  id,
542  id2,
543  id3);
545 }
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
bool mReportUnimplemented
Definition: logger.h:222
static void distributeEvent(const std::string &msg)

Field Documentation

◆ mDebugLog

bool Logger::mDebugLog
private

Definition at line 221 of file logger.h.

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

◆ mDelayedLog

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

Definition at line 217 of file logger.h.

Referenced by flush(), and log_r().

◆ mLogFile

FILE* Logger::mLogFile
private

Definition at line 216 of file logger.h.

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

◆ mLogToStandardOut

bool Logger::mLogToStandardOut
private

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

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

◆ mReportUnimplemented

bool Logger::mReportUnimplemented
private

Definition at line 222 of file logger.h.

Referenced by setReportUnimplemented(), and unimplemented().

◆ mThreadLocked

volatile bool Logger::mThreadLocked
private

Definition at line 219 of file logger.h.

Referenced by flush(), and log_r().


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