From 14db1066fc72982e1d862183102fd6f79b6cd2ce Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Fri, 1 Jun 2012 17:39:23 -0300 Subject: [PATCH] change logger --- src/framework/application.cpp | 8 +-- src/framework/core/configmanager.cpp | 2 +- src/framework/core/eventdispatcher.cpp | 2 +- src/framework/core/filestream.cpp | 46 ++++++++--------- src/framework/core/logger.cpp | 2 +- src/framework/core/logger.h | 23 +++++---- src/framework/core/module.cpp | 10 ++-- src/framework/core/modulemanager.cpp | 12 ++--- src/framework/core/resourcemanager.cpp | 10 ++-- src/framework/graphics/fontmanager.cpp | 4 +- src/framework/graphics/framebuffer.cpp | 4 +- src/framework/graphics/graphics.cpp | 8 +-- src/framework/graphics/image.cpp | 2 +- src/framework/graphics/particleemitter.cpp | 2 +- src/framework/graphics/particlemanager.cpp | 2 +- src/framework/graphics/shader.cpp | 2 +- src/framework/graphics/shaderprogram.cpp | 8 +-- src/framework/graphics/texture.cpp | 6 +-- src/framework/graphics/texturemanager.cpp | 2 +- src/framework/luascript/luainterface.cpp | 13 +++-- src/framework/luascript/luavaluecasts.h | 4 +- src/framework/net/protocol.cpp | 12 ++--- src/framework/platform/unixcrashhandler.cpp | 8 +-- src/framework/platform/win32crashhandler.cpp | 6 +-- src/framework/platform/win32window.cpp | 34 ++++++------- src/framework/platform/x11window.cpp | 52 ++++++++++---------- src/framework/sound/oggsoundfile.cpp | 2 +- src/framework/sound/soundbuffer.cpp | 6 +-- src/framework/sound/soundfile.cpp | 4 +- src/framework/sound/soundmanager.cpp | 10 ++-- src/framework/sound/streamsoundsource.cpp | 12 ++--- src/framework/ui/uianchorlayout.cpp | 2 +- src/framework/ui/uiframecounter.h | 48 ------------------ src/framework/ui/uimanager.cpp | 10 ++-- src/framework/ui/uiwidget.cpp | 42 ++++++++-------- src/otclient/core/container.cpp | 4 +- src/otclient/core/game.cpp | 14 +++--- src/otclient/core/item.cpp | 4 +- src/otclient/core/mapview.cpp | 6 +-- src/otclient/core/spritemanager.cpp | 4 +- src/otclient/core/statictext.cpp | 2 +- src/otclient/core/thing.cpp | 2 +- src/otclient/core/thingstype.cpp | 4 +- src/otclient/net/protocolcodes.h | 6 +-- src/otclient/net/protocolgameparse.cpp | 46 ++++++++--------- src/otclient/net/protocolgamesend.cpp | 2 +- src/otclient/net/protocollogin.cpp | 2 +- src/otclient/otclient.cpp | 8 +-- 48 files changed, 237 insertions(+), 287 deletions(-) delete mode 100644 src/framework/ui/uiframecounter.h diff --git a/src/framework/application.cpp b/src/framework/application.cpp index 22093ca7..ebe69c37 100644 --- a/src/framework/application.cpp +++ b/src/framework/application.cpp @@ -84,11 +84,11 @@ void Application::init(const std::vector& args) // setup configs write directory if(!g_resources.setupWriteDir(m_appName)) - logError("Could not setup write directory"); + g_logger.error("Could not setup write directory"); // load configs if(!g_configs.load("/config.otml")) - logInfo("Using default configurations."); + g_logger.info("Using default configurations."); // setup platform window g_ui.init(); @@ -159,7 +159,7 @@ void Application::terminate() m_foreground = nullptr; - logInfo("Application ended successfully."); + g_logger.info("Application ended successfully."); } void Application::run() @@ -256,7 +256,7 @@ void Application::run() void Application::exit() { - logInfo("Exiting application.."); + g_logger.info("Exiting application.."); m_stopping = true; } diff --git a/src/framework/core/configmanager.cpp b/src/framework/core/configmanager.cpp index bc7bfe90..dbeba9de 100644 --- a/src/framework/core/configmanager.cpp +++ b/src/framework/core/configmanager.cpp @@ -45,7 +45,7 @@ bool ConfigManager::load(const std::string& file) m_confsDoc = confsDoc; return true; } catch(stdext::exception& e) { - logError("Unable to load configuration file: %s", e.what()); + g_logger.error(stdext::format("Unable to load configuration file: %s", e.what())); return false; } } diff --git a/src/framework/core/eventdispatcher.cpp b/src/framework/core/eventdispatcher.cpp index 07fc59a6..5248dc13 100644 --- a/src/framework/core/eventdispatcher.cpp +++ b/src/framework/core/eventdispatcher.cpp @@ -56,7 +56,7 @@ void EventDispatcher::poll() if(count > 50) { static Timer reportTimer; if(reportTimer.running() && reportTimer.ticksElapsed() > 250) { - logError("ATTENTION the event list is not getting empty, this could be caused by some bad code"); + g_logger.error("ATTENTION the event list is not getting empty, this could be caused by some bad code"); reportTimer.restart(); } break; diff --git a/src/framework/core/filestream.cpp b/src/framework/core/filestream.cpp index 02fee053..3e74061a 100644 --- a/src/framework/core/filestream.cpp +++ b/src/framework/core/filestream.cpp @@ -39,7 +39,7 @@ FileStream::~FileStream() void FileStream::cache() { if(!m_fileHandle) - logTraceError("no file handle to cache"); + g_logger.traceError("no file handle to cache"); // cache entire file into cache buffer m_cacheReadPos = PHYSFS_tell(m_fileHandle); @@ -48,7 +48,7 @@ void FileStream::cache() m_cacheBuffer.resize(size); int res = PHYSFS_read(m_fileHandle, &m_cacheBuffer[0], size, 1); if(res == -1) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); PHYSFS_close(m_fileHandle); m_fileHandle = nullptr; @@ -58,7 +58,7 @@ bool FileStream::close() { if(m_fileHandle) { if(PHYSFS_isInit() && PHYSFS_close(m_fileHandle) == 0) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); m_fileHandle = nullptr; return true; @@ -75,7 +75,7 @@ bool FileStream::flush() return false; if(PHYSFS_flush(m_fileHandle) == 0) { - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); return false; } return true; @@ -86,7 +86,7 @@ int FileStream::read(void *buffer, int size, int nmemb) if(m_fileHandle) { int res = PHYSFS_read(m_fileHandle, buffer, size, nmemb); if(res == -1) { - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); return 0; } return res; @@ -111,7 +111,7 @@ bool FileStream::write(void *buffer, int count) return false; if(PHYSFS_write(m_fileHandle, buffer, 1, count) != count) { - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); return false; } @@ -122,12 +122,12 @@ bool FileStream::seek(int pos) { if(m_fileHandle) { if(PHYSFS_seek(m_fileHandle, pos) == 0) { - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); return false; } } else { if(pos > (int)m_cacheBuffer.size() || pos < 0) { - logTraceError("operation failed on '%s': seek pos cannot be greater than file length", m_name); + g_logger.traceError(stdext::format("operation failed on '%s': seek pos cannot be greater than file length", m_name)); return false; } m_cacheReadPos = pos; @@ -156,10 +156,10 @@ uint8 FileStream::getU8() uint8 v = 0; if(m_fileHandle) { if(PHYSFS_read(m_fileHandle, &v, 1, 1) != 1) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); } else { if(m_cacheReadPos+1 > m_cacheBuffer.size()) { - logTraceError("operation failed on '%s': reached file eof", m_name); + g_logger.traceError(stdext::format("operation failed on '%s': reached file eof", m_name)); return 0; } @@ -174,10 +174,10 @@ uint16 FileStream::getU16() uint16 v = 0; if(m_fileHandle) { if(PHYSFS_readULE16(m_fileHandle, &v) == 0) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); } else { if(m_cacheReadPos+2 > m_cacheBuffer.size()) { - logTraceError("operation failed on '%s': reached file eof", m_name); + g_logger.traceError(stdext::format("operation failed on '%s': reached file eof", m_name)); return 0; } @@ -192,10 +192,10 @@ uint32 FileStream::getU32() uint32 v = 0; if(m_fileHandle) { if(PHYSFS_readULE32(m_fileHandle, &v) == 0) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); } else { if(m_cacheReadPos+4 > m_cacheBuffer.size()) { - logTraceError("operation failed on '%s': reached file eof", m_name); + g_logger.traceError(stdext::format("operation failed on '%s': reached file eof", m_name)); return 0; } @@ -210,10 +210,10 @@ uint64 FileStream::getU64() uint64 v = 0; if(m_fileHandle) { if(PHYSFS_readULE64(m_fileHandle, (PHYSFS_uint64*)&v) == 0) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); } else { if(m_cacheReadPos+8 > m_cacheBuffer.size()) { - logTraceError("operation failed on '%s': reached file eof", m_name); + g_logger.traceError(stdext::format("operation failed on '%s': reached file eof", m_name)); return 0; } @@ -231,12 +231,12 @@ std::string FileStream::getString() char buffer[8192]; if(m_fileHandle) { if(PHYSFS_read(m_fileHandle, buffer, 1, len) == 0) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); else str = std::string(buffer, len); } else { if(m_cacheReadPos+len > m_cacheBuffer.size()) { - logTraceError("operation failed on '%s': reached file eof", m_name); + g_logger.traceError(stdext::format("operation failed on '%s': reached file eof", m_name)); return 0; } @@ -244,7 +244,7 @@ std::string FileStream::getString() m_cacheReadPos += len; } } else { - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); } return str; } @@ -252,23 +252,23 @@ std::string FileStream::getString() void FileStream::addU8(uint8 v) { if(PHYSFS_write(m_fileHandle, &v, 1, 1) != 1) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); } void FileStream::addU16(uint8 v) { if(PHYSFS_writeULE16(m_fileHandle, v) == 0) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); } void FileStream::addU32(uint8 v) { if(PHYSFS_writeULE32(m_fileHandle, v) == 0) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); } void FileStream::addU64(uint8 v) { if(PHYSFS_writeULE64(m_fileHandle, v) == 0) - logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); + g_logger.traceError(stdext::format("operation failed on '%s': %s", m_name, PHYSFS_getLastError())); } diff --git a/src/framework/core/logger.cpp b/src/framework/core/logger.cpp index 18e8062d..30adb9ba 100644 --- a/src/framework/core/logger.cpp +++ b/src/framework/core/logger.cpp @@ -89,7 +89,7 @@ void Logger::setLogFile(const std::string& file) { m_outFile.open(file.c_str(), std::ios::out | std::ios::app); if(!m_outFile.is_open() || !m_outFile.good()) { - logError("Unable to save log to '%s'", file); + g_logger.error(stdext::format("Unable to save log to '%s'", file)); return; } diff --git a/src/framework/core/logger.h b/src/framework/core/logger.h index 092622bd..2ed2f338 100644 --- a/src/framework/core/logger.h +++ b/src/framework/core/logger.h @@ -44,6 +44,12 @@ public: void log(Fw::LogLevel level, const std::string& message); void logFunc(Fw::LogLevel level, const std::string& message, std::string prettyFunction); + void debug(const std::string& what) { log(Fw::LogDebug, what); } + void info(const std::string& what) { log(Fw::LogInfo, what); } + void warning(const std::string& what) { log(Fw::LogWarning, what); } + void error(const std::string& what) { log(Fw::LogError, what); } + void fatal(const std::string& what) { log(Fw::LogError, what); } + void fireOldMessages(); void setLogFile(const std::string& file); void setOnLog(const OnLogCallback& onLog) { m_onLog = onLog; } @@ -56,18 +62,11 @@ private: extern Logger g_logger; -// specialized logging -#define logDebug(...) g_logger.log(Fw::LogDebug, stdext::format(__VA_ARGS__)) -#define logInfo(...) g_logger.log(Fw::LogInfo, stdext::format(__VA_ARGS__)) -#define logWarning(...) g_logger.log(Fw::LogWarning, stdext::format(__VA_ARGS__)) -#define logError(...) g_logger.log(Fw::LogError, stdext::format(__VA_ARGS__)) -#define logFatal(...) g_logger.log(Fw::LogFatal, stdext::format(__VA_ARGS__)) - -#define logTrace() g_logger.logFunc(Fw::LogDebug, "", __PRETTY_FUNCTION__) -#define logTraceDebug(...) g_logger.logFunc(Fw::LogDebug, stdext::format(__VA_ARGS__), __PRETTY_FUNCTION__) -#define logTraceInfo(...) g_logger.logFunc(Fw::LogInfo, stdext::format(__VA_ARGS__), __PRETTY_FUNCTION__) -#define logTraceWarning(...) g_logger.logFunc(Fw::LogWarning, stdext::format(__VA_ARGS__), __PRETTY_FUNCTION__) -#define logTraceError(...) g_logger.logFunc(Fw::LogError, stdext::format(__VA_ARGS__), __PRETTY_FUNCTION__) +#define trace() logFunc(Fw::LogDebug, "", __PRETTY_FUNCTION__) +#define traceDebug(a) logFunc(Fw::LogDebug, a, __PRETTY_FUNCTION__) +#define traceInfo(a) logFunc(Fw::LogInfo, a, __PRETTY_FUNCTION__) +#define traceWarning(a) logFunc(Fw::LogWarning, a, __PRETTY_FUNCTION__) +#define traceError(a) logFunc(Fw::LogError, a, __PRETTY_FUNCTION__) #define logTraceCounter() { \ static int __count = 0; \ diff --git a/src/framework/core/module.cpp b/src/framework/core/module.cpp index d77abce8..155d229e 100644 --- a/src/framework/core/module.cpp +++ b/src/framework/core/module.cpp @@ -39,12 +39,12 @@ bool Module::load() for(const std::string& depName : m_dependencies) { ModulePtr dep = g_modules.getModule(depName); if(!dep) { - logError("Unable to load module '%s' because dependency '%s' was not found", m_name, depName); + g_logger.error(stdext::format("Unable to load module '%s' because dependency '%s' was not found", m_name, depName)); return false; } if(!dep->isLoaded() && !dep->load()) { - logError("Unable to load module '%s' because dependency '%s' has failed to load", m_name, depName); + g_logger.error(stdext::format("Unable to load module '%s' because dependency '%s' has failed to load", m_name, depName)); return false; } } @@ -53,13 +53,13 @@ bool Module::load() m_loadCallback(); m_loaded = true; - logInfo("Loaded module '%s'", m_name); + g_logger.info(stdext::format("Loaded module '%s'", m_name)); g_modules.updateModuleLoadOrder(asModule()); for(const std::string& modName : m_loadLaterModules) { ModulePtr dep = g_modules.getModule(modName); if(!dep) - logError("Unable to find module '%s' required by '%s'", modName, m_name); + g_logger.error(stdext::format("Unable to find module '%s' required by '%s'", modName, m_name)); else if(!dep->isLoaded()) dep->load(); } @@ -73,7 +73,7 @@ void Module::unload() if(m_unloadCallback) m_unloadCallback(); m_loaded = false; - logInfo("Unloaded module '%s'", m_name); + g_logger.info(stdext::format("Unloaded module '%s'", m_name)); g_modules.updateModuleLoadOrder(asModule()); } } diff --git a/src/framework/core/modulemanager.cpp b/src/framework/core/modulemanager.cpp index 32e3d644..4203e174 100644 --- a/src/framework/core/modulemanager.cpp +++ b/src/framework/core/modulemanager.cpp @@ -54,7 +54,7 @@ void ModuleManager::autoLoadModules(int maxPriority) break; ModulePtr module = pair.second; if(!module->isLoaded() && !module->load()) - logFatal("A required module has failed to load, cannot continue to run."); + g_logger.fatal("A required module has failed to load, cannot continue to run."); } } @@ -70,14 +70,14 @@ void ModuleManager::discoverModulesPath() for(const std::string& dir : possibleModulesDirs) { // try to add module directory if(g_resources.addToSearchPath(dir, false)) { - logInfo("Using modules directory '%s'", dir.c_str()); + g_logger.info(stdext::format("Using modules directory '%s'", dir.c_str())); found = true; break; } } if(!found) - logFatal("Could not find modules directory"); + g_logger.fatal("Could not find modules directory"); // search for addons directory std::string possibleAddonsDirs[] = { "addons", @@ -88,7 +88,7 @@ void ModuleManager::discoverModulesPath() for(const std::string& dir : possibleAddonsDirs) { // try to add module directory if(g_resources.addToSearchPath(dir, true)) { - logInfo("Using addons directory '%s'", dir.c_str()); + g_logger.info(stdext::format("Using addons directory '%s'", dir.c_str())); found = true; break; } @@ -116,7 +116,7 @@ ModulePtr ModuleManager::discoverModule(const std::string& moduleFile) if(push) m_modules.push_back(module); } catch(stdext::exception& e) { - logError("Unable to discover module from file '%s': %s", moduleFile, e.what()); + g_logger.error(stdext::format("Unable to discover module from file '%s': %s", moduleFile, e.what())); } return module; } @@ -125,7 +125,7 @@ void ModuleManager::ensureModuleLoaded(const std::string& moduleName) { ModulePtr module = g_modules.getModule(moduleName); if(!module || !module->load()) - logFatal("Unable to load '%s' module", moduleName); + g_logger.fatal(stdext::format("Unable to load '%s' module", moduleName)); } void ModuleManager::unloadModules() diff --git a/src/framework/core/resourcemanager.cpp b/src/framework/core/resourcemanager.cpp index 492d039b..7831016a 100644 --- a/src/framework/core/resourcemanager.cpp +++ b/src/framework/core/resourcemanager.cpp @@ -118,7 +118,7 @@ bool ResourceManager::saveFile(const std::string& fileName, const uchar* data, u PHYSFS_file* file = PHYSFS_openWrite(fileName.c_str()); if(!file) { - logError(PHYSFS_getLastError()); + g_logger.error(PHYSFS_getLastError()); return false; } @@ -150,7 +150,7 @@ FileStreamPtr ResourceManager::openFile(const std::string& fileName) std::string fullPath = resolvePath(fileName); PHYSFS_File* file = PHYSFS_openRead(fullPath.c_str()); if(!file) { - logTraceError("unable to open file '%s': %s", fullPath, PHYSFS_getLastError()); + g_logger.error(stdext::format("unable to open file '%s': %s", fullPath, PHYSFS_getLastError())); return nullptr; } return FileStreamPtr(new FileStream(fullPath, file)); @@ -160,7 +160,7 @@ FileStreamPtr ResourceManager::appendFile(const std::string& fileName) { PHYSFS_File* file = PHYSFS_openAppend(fileName.c_str()); if(!file) { - logTraceError("failed to append file '%s': %s", fileName, PHYSFS_getLastError()); + g_logger.error(stdext::format("failed to append file '%s': %s", fileName, PHYSFS_getLastError())); return nullptr; } return FileStreamPtr(new FileStream(fileName, file)); @@ -170,7 +170,7 @@ FileStreamPtr ResourceManager::createFile(const std::string& fileName) { PHYSFS_File* file = PHYSFS_openWrite(fileName.c_str()); if(!file) { - logTraceError("failed to create file '%s': %s", fileName, PHYSFS_getLastError()); + g_logger.error(stdext::format("failed to create file '%s': %s", fileName, PHYSFS_getLastError())); return nullptr; } return FileStreamPtr(new FileStream(fileName, file)); @@ -211,7 +211,7 @@ std::string ResourceManager::resolvePath(const std::string& path) fullPath += path; } if(!(boost::starts_with(fullPath, "/"))) - logTraceWarning("the following file path is not fully resolved: %s", path); + g_logger.traceWarning(stdext::format("the following file path is not fully resolved: %s", path)); boost::replace_all(fullPath, "//", "/"); return fullPath; } diff --git a/src/framework/graphics/fontmanager.cpp b/src/framework/graphics/fontmanager.cpp index 2b07d206..7f96e46f 100644 --- a/src/framework/graphics/fontmanager.cpp +++ b/src/framework/graphics/fontmanager.cpp @@ -67,7 +67,7 @@ bool FontManager::importFont(std::string fontFile) return true; } catch(stdext::exception& e) { - logError("Unable to load font from file '%s': %s", fontFile, e.what()); + g_logger.error(stdext::format("Unable to load font from file '%s': %s", fontFile, e.what())); return false; } } @@ -90,7 +90,7 @@ FontPtr FontManager::getFont(const std::string& fontName) } // when not found, fallback to default font - logError("font '%s' not found", fontName); + g_logger.error(stdext::format("font '%s' not found", fontName)); return getDefaultFont(); } diff --git a/src/framework/graphics/framebuffer.cpp b/src/framework/graphics/framebuffer.cpp index fe4fc76e..9963a9a7 100644 --- a/src/framework/graphics/framebuffer.cpp +++ b/src/framework/graphics/framebuffer.cpp @@ -45,7 +45,7 @@ void FrameBuffer::internalCreate() if(g_graphics.canUseFBO()) { glGenFramebuffers(1, &m_fbo); if(!m_fbo) - logFatal("Unable to create framebuffer object"); + g_logger.fatal("Unable to create framebuffer object"); } } @@ -72,7 +72,7 @@ void FrameBuffer::resize(const Size& size) GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if(status != GL_FRAMEBUFFER_COMPLETE) - logFatal("Unable to setup framebuffer object"); + g_logger.fatal("Unable to setup framebuffer object"); internalRelease(); } else { m_screenBackup = TexturePtr(new Texture(size.width(), size.height())); diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index f3cdf857..117d0dff 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -45,8 +45,8 @@ Graphics::Graphics() void Graphics::init() { - logInfo("GPU %s", glGetString(GL_RENDERER)); - logInfo("OpenGL %s", glGetString(GL_VERSION)); + g_logger.info(stdext::format("GPU %s", glGetString(GL_RENDERER))); + g_logger.info(stdext::format("OpenGL %s", glGetString(GL_VERSION))); #if OPENGL_ES==2 g_painterOGL2 = new PainterOGL2; @@ -56,7 +56,7 @@ void Graphics::init() // init GL extensions GLenum err = glewInit(); if(err != GLEW_OK) - logFatal("Unable to init GLEW: %s", glewGetErrorString(err)); + g_logger.fatal(stdext::format("Unable to init GLEW: %s", glewGetErrorString(err))); // overwrite framebuffer API if needed if(GLEW_EXT_framebuffer_object && !GLEW_ARB_framebuffer_object) { @@ -162,7 +162,7 @@ bool Graphics::selectPainterEngine(PainterEngine painterEngine) #endif if(!found) - logFatal("Neither OpenGL 1.0 nor OpenGL 2.0 painter engine is supported by your platform, " + g_logger.fatal("Neither OpenGL 1.0 nor OpenGL 2.0 painter engine is supported by your platform, " "try updating your graphics drivers or your hardware and then run again."); // switch painters GL state diff --git a/src/framework/graphics/image.cpp b/src/framework/graphics/image.cpp index 3df1c4b8..31bf49b0 100644 --- a/src/framework/graphics/image.cpp +++ b/src/framework/graphics/image.cpp @@ -46,7 +46,7 @@ ImagePtr Image::load(const std::string& file) // load image file data image = loadPNG(file); } catch(stdext::exception& e) { - logError("unable to load image '%s': %s", file, e.what()); + g_logger.error(stdext::format("unable to load image '%s': %s", file, e.what())); } return image; } diff --git a/src/framework/graphics/particleemitter.cpp b/src/framework/graphics/particleemitter.cpp index c7a8d295..5ea25d61 100644 --- a/src/framework/graphics/particleemitter.cpp +++ b/src/framework/graphics/particleemitter.cpp @@ -172,7 +172,7 @@ bool ParticleEmitter::load(const OTMLNodePtr& node) m_pColorsStops.push_back(0); if(m_pColors.size() != m_pColorsStops.size()) { - logError("particle colors must be equal to colorstops-1"); + g_logger.error(stdext::format("particle colors must be equal to colorstops-1")); return false; } diff --git a/src/framework/graphics/particlemanager.cpp b/src/framework/graphics/particlemanager.cpp index fca6d4ba..84aa7214 100644 --- a/src/framework/graphics/particlemanager.cpp +++ b/src/framework/graphics/particlemanager.cpp @@ -39,7 +39,7 @@ bool ParticleManager::load(const std::string& filename) } return true; } catch(stdext::exception& e) { - logError("could not load particles: %s", e.what()); + g_logger.error(stdext::format("could not load particles: %s", e.what())); return false; } } diff --git a/src/framework/graphics/shader.cpp b/src/framework/graphics/shader.cpp index d303ed0a..ba6670e6 100644 --- a/src/framework/graphics/shader.cpp +++ b/src/framework/graphics/shader.cpp @@ -36,7 +36,7 @@ Shader::Shader(Shader::ShaderType shaderType) } if(!m_shaderId) - logFatal("Unable to create GL shader"); + g_logger.fatal("Unable to create GL shader"); } Shader::~Shader() diff --git a/src/framework/graphics/shaderprogram.cpp b/src/framework/graphics/shaderprogram.cpp index 6fa29cc2..24618ea7 100644 --- a/src/framework/graphics/shaderprogram.cpp +++ b/src/framework/graphics/shaderprogram.cpp @@ -30,7 +30,7 @@ ShaderProgram::ShaderProgram() m_programId = glCreateProgram(); m_uniformLocations.fill(-1); if(!m_programId) - logFatal("Unable to create GL shader program"); + g_logger.fatal("Unable to create GL shader program"); } ShaderProgram::~ShaderProgram() @@ -48,7 +48,7 @@ bool ShaderProgram::addShader(const ShaderPtr& shader) { bool ShaderProgram::addShaderFromSourceCode(Shader::ShaderType shaderType, const std::string& sourceCode) { ShaderPtr shader(new Shader(shaderType)); if(!shader->compileSourceCode(sourceCode)) { - logError("failed to compile shader: %s", shader->log()); + g_logger.error(stdext::format("failed to compile shader: %s", shader->log())); return false; } return addShader(shader); @@ -57,7 +57,7 @@ bool ShaderProgram::addShaderFromSourceCode(Shader::ShaderType shaderType, const bool ShaderProgram::addShaderFromSourceFile(Shader::ShaderType shaderType, const std::string& sourceFile) { ShaderPtr shader(new Shader(shaderType)); if(!shader->compileSourceFile(sourceFile)) { - logError("failed to compile shader: %s", shader->log()); + g_logger.error(stdext::format("failed to compile shader: %s", shader->log())); return false; } return addShader(shader); @@ -92,7 +92,7 @@ bool ShaderProgram::link() m_linked = (value != GL_FALSE); if(!m_linked) - logTraceWarning(log()); + g_logger.traceWarning(log()); return m_linked; } diff --git a/src/framework/graphics/texture.cpp b/src/framework/graphics/texture.cpp index d96c2bf1..2992bc24 100644 --- a/src/framework/graphics/texture.cpp +++ b/src/framework/graphics/texture.cpp @@ -82,10 +82,10 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int // checks texture max size if(std::max(glSize.width(), glSize.height()) > g_graphics.getMaxTextureSize()) { - logError("loading texture with size %dx%d failed, " + g_logger.error(stdext::format("loading texture with size %dx%d failed, " "the maximum size allowed by the graphics card is %dx%d," "to prevent crashes the texture will be displayed as a blank texture", - width, height, g_graphics.getMaxTextureSize(), g_graphics.getMaxTextureSize()); + width, height, g_graphics.getMaxTextureSize(), g_graphics.getMaxTextureSize())); //TODO: make a workaround, could be bilinear scaling the texture return 0; } @@ -149,7 +149,7 @@ void Texture::generateMipmaps() //FIXME: disabled because mipmaps size needs to be in base of 2, // and the current algorithmn does not support that //generateSoftwareMipmaps(getPixels()); - logTraceError("non power of 2."); + g_logger.traceError("non power of 2."); } } diff --git a/src/framework/graphics/texturemanager.cpp b/src/framework/graphics/texturemanager.cpp index 3a76dc35..ff4128c9 100644 --- a/src/framework/graphics/texturemanager.cpp +++ b/src/framework/graphics/texturemanager.cpp @@ -57,7 +57,7 @@ TexturePtr TextureManager::getTexture(const std::string& fileName) g_resources.loadFile(filePath, fin); texture = loadPNG(fin); } catch(stdext::exception& e) { - logError("unable to load texture '%s': %s", fileName, e.what()); + g_logger.error(stdext::format("unable to load texture '%s': %s", fileName, e.what())); texture = g_graphics.getEmptyTexture(); } diff --git a/src/framework/luascript/luainterface.cpp b/src/framework/luascript/luainterface.cpp index 42afca01..d77828b8 100644 --- a/src/framework/luascript/luainterface.cpp +++ b/src/framework/luascript/luainterface.cpp @@ -480,7 +480,7 @@ int LuaInterface::protectedCall(int numArgs, int requestedResults) throw LuaException("attempt to call a non function value", 0); } } catch(LuaException &e) { - logError("protected lua call failed: %s", e.what()); + g_logger.error(stdext::format("protected lua call failed: %s", e.what())); } // pushes nil values if needed @@ -515,7 +515,7 @@ int LuaInterface::luaScriptLoader(lua_State* L) g_lua.loadScript(fileName); return 1; } catch(LuaException& e) { - logError("failed to load script file '%s': %s", fileName, e.what()); + g_logger.error(stdext::format("failed to load script file '%s': %s", fileName, e.what())); return 0; } } @@ -531,7 +531,7 @@ int LuaInterface::luaScriptRunner(lua_State* L) g_lua.call(0, LUA_MULTRET); return g_lua.stackSize(); } catch(LuaException& e) { - logError("failed to load script file '%s': %s", fileName, e.what()); + g_logger.error(stdext::format("failed to load script file '%s': %s", fileName, e.what())); return 0; } } @@ -548,7 +548,7 @@ int LuaInterface::luaScriptsRunner(lua_State* L) g_lua.loadScript(directory + "/" + fileName); g_lua.call(0, 0); } catch(LuaException& e) { - logError("failed to load script file '%s': %s", fileName, e.what()); + g_logger.error(stdext::format("failed to load script file '%s': %s", fileName, e.what())); } } return 0; @@ -583,7 +583,7 @@ int LuaInterface::luaCppFunctionCallback(lua_State* L) g_lua.m_cppCallbackDepth--; assert(numRets == g_lua.stackSize()); } catch(LuaException &e) { - logError("lua cpp callback failed: %s", e.what()); + g_logger.error(stdext::format("lua cpp callback failed: %s", e.what())); } return numRets; @@ -606,7 +606,7 @@ void LuaInterface::createLuaState() // creates lua state L = luaL_newstate(); if(!L) - logFatal("Unable to create lua state"); + g_logger.fatal("Unable to create lua state"); // load lua standard libraries luaL_openlibs(L); @@ -779,7 +779,6 @@ void LuaInterface::getStackFunction(int level) void LuaInterface::getRef(int ref) { lua_rawgeti(L, LUA_REGISTRYINDEX, ref); - //logTraceDebug(ref); } void LuaInterface::getWeakRef(int weakRef) diff --git a/src/framework/luascript/luavaluecasts.h b/src/framework/luascript/luavaluecasts.h index d1351629..afa13674 100644 --- a/src/framework/luascript/luavaluecasts.h +++ b/src/framework/luascript/luavaluecasts.h @@ -205,7 +205,7 @@ bool luavalue_cast(int index, std::function& func) { "did you forget to hold a reference for that function?", 0); } } catch(LuaException& e) { - logError("lua function callback failed: %s", e.what()); + g_logger.error(stdext::format("lua function callback failed: %s", e.what())); } }; return true; @@ -239,7 +239,7 @@ luavalue_cast(int index, std::function& func) { "did you forget to hold a reference for that function?", 0); } } catch(LuaException& e) { - logError("lua function callback failed: %s", e.what()); + g_logger.error(stdext::format("lua function callback failed: %s", e.what())); } return Ret(); }; diff --git a/src/framework/net/protocol.cpp b/src/framework/net/protocol.cpp index c6d627a5..8f07216c 100644 --- a/src/framework/net/protocol.cpp +++ b/src/framework/net/protocol.cpp @@ -114,26 +114,26 @@ void Protocol::internalRecvData(uint8* buffer, uint16 size) { // process data only if really connected if(!isConnected()) { - logTraceError("received data while disconnected"); + g_logger.traceError("received data while disconnected"); return; } m_inputMessage->fillBuffer(buffer, size); if(m_checksumEnabled && !m_inputMessage->readChecksum()) { - logTraceError("got a network message with invalid checksum"); + g_logger.traceError("got a network message with invalid checksum"); return; } if(m_xteaEncryptionEnabled) { if(!xteaDecrypt(m_inputMessage)) { - logTraceError("failed to decrypt message"); + g_logger.traceError("failed to decrypt message"); return; } } else { int size = m_inputMessage->getU16(); if(size != m_inputMessage->getUnreadSize()) { - logTraceError("invalid message size"); + g_logger.traceError("invalid message size"); return; } } @@ -155,7 +155,7 @@ bool Protocol::xteaDecrypt(const InputMessagePtr& inputMessage) { uint16 encryptedSize = inputMessage->getUnreadSize(); if(encryptedSize % 8 != 0) { - logTraceError("invalid encrypted network message"); + g_logger.traceError("invalid encrypted network message"); return false; } @@ -179,7 +179,7 @@ bool Protocol::xteaDecrypt(const InputMessagePtr& inputMessage) uint16 decryptedSize = inputMessage->getU16() + 2; int sizeDelta = decryptedSize - encryptedSize; if(sizeDelta > 0 || -sizeDelta > encryptedSize) { - logTraceError("invalid decrypted a network message"); + g_logger.traceError("invalid decrypted a network message"); return false; } diff --git a/src/framework/platform/unixcrashhandler.cpp b/src/framework/platform/unixcrashhandler.cpp index ce8dbd2e..0d8ef790 100644 --- a/src/framework/platform/unixcrashhandler.cpp +++ b/src/framework/platform/unixcrashhandler.cpp @@ -36,7 +36,7 @@ void crashHandler(int signum, siginfo_t* info, void* secret) { - logError("Application crashed"); + g_logger.error("Application crashed"); std::stringstream ss; ss << stdext::format("app name: %s\n", g_app->getName()); @@ -100,7 +100,7 @@ void crashHandler(int signum, siginfo_t* info, void* secret) free(tracebackBuffer); } - logInfo(ss.str()); + g_logger.info(ss.str()); std::string fileName = "crash_report.txt"; std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::app); @@ -109,9 +109,9 @@ void crashHandler(int signum, siginfo_t* info, void* secret) fout << ss.str(); fout << "\n"; fout.close(); - logInfo("Crash report saved to file %s", fileName.c_str()); + g_logger.info(stdext::format("Crash report saved to file %s", fileName.c_str())); } else - logError("Failed to save crash report!"); + g_logger.error("Failed to save crash report!"); signal(SIGILL, SIG_DFL); signal(SIGSEGV, SIG_DFL); diff --git a/src/framework/platform/win32crashhandler.cpp b/src/framework/platform/win32crashhandler.cpp index 0af021c9..8fd51abe 100644 --- a/src/framework/platform/win32crashhandler.cpp +++ b/src/framework/platform/win32crashhandler.cpp @@ -124,7 +124,7 @@ LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e) SymCleanup(GetCurrentProcess()); // print in stdout - logInfo(ss.str()); + g_logger.info(ss.str()); // write stacktrace to crash_report.txt char dir[MAX_PATH]; @@ -134,9 +134,9 @@ LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e) if(fout.is_open() && fout.good()) { fout << ss.str(); fout.close(); - logInfo("Crash report saved to file %s", fileName); + g_logger.info("Crash report saved to file %s", fileName); } else - logError("Failed to save crash report!"); + g_logger.error("Failed to save crash report!"); // inform the user std::string msg = stdext::format( diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index 6811bff9..6bc95e76 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -203,15 +203,15 @@ void WIN32Window::terminate() { if(m_glContext) { if(!wglMakeCurrent(NULL, NULL)) - logError("Release of dc and rc failed."); + g_logger.error("Release of dc and rc failed."); if(!wglDeleteContext(m_glContext)) - logError("Release rendering context failed."); + g_logger.error("Release rendering context failed."); m_glContext = NULL; } if(m_deviceContext) { if(!ReleaseDC(m_window, m_deviceContext)) - logError("Release device context failed."); + g_logger.error("Release device context failed."); m_deviceContext = NULL; } @@ -222,13 +222,13 @@ void WIN32Window::terminate() if(m_window) { if(!DestroyWindow(m_window)) - logError("ERROR: Destroy window failed."); + g_logger.error("ERROR: Destroy window failed."); m_window = NULL; } if(m_instance) { if(!UnregisterClassA(g_app->getName().c_str(), m_instance)) - logError("UnregisterClassA failed"); + g_logger.error("UnregisterClassA failed"); m_instance = NULL; } } @@ -256,7 +256,7 @@ void WIN32Window::internalRegisterWindowClass() wc.lpszClassName = g_app->getName().c_str(); if(!RegisterClassA(&wc)) - logFatal("Failed to register the window class."); + g_logger.fatal("Failed to register the window class."); } void WIN32Window::internalCreateWindow() @@ -286,13 +286,13 @@ void WIN32Window::internalCreateWindow() NULL); if(!m_window) - logFatal("Unable to create window"); + g_logger.fatal("Unable to create window"); ShowWindow(m_window, SW_HIDE); m_deviceContext = GetDC(m_window); if(!m_deviceContext) - logFatal("GetDC failed"); + g_logger.fatal("GetDC failed"); } void WIN32Window::internalChooseGLVisual() @@ -317,20 +317,20 @@ void WIN32Window::internalChooseGLVisual() pixelFormat = ChoosePixelFormat(m_deviceContext, &pfd); if(!pixelFormat) - logFatal("Could not find a suitable pixel format"); + g_logger.fatal("Could not find a suitable pixel format"); pfd.cStencilBits = 8; if(!SetPixelFormat(m_deviceContext, pixelFormat, &pfd)) - logFatal("Could not set the pixel format"); + g_logger.fatal("Could not set the pixel format"); } void WIN32Window::internalCreateGLContext() { if(!(m_glContext = wglCreateContext(m_deviceContext))) - logFatal("Unable to create GL context"); + g_logger.fatal("Unable to create GL context"); if(!wglMakeCurrent(m_deviceContext, m_glContext)) - logFatal("Unable to set GLX context on WIN32 window"); + g_logger.fatal("Unable to set GLX context on WIN32 window"); } bool WIN32Window::isExtensionSupported(const char *ext) @@ -679,18 +679,18 @@ void WIN32Window::setMouseCursor(const std::string& file, const Point& hotSpot) apng_data apng; if(load_apng(fin, &apng) != 0) { - logTraceError("unable to load png file %s", file); + g_logger.traceError(stdext::format("unable to load png file %s", file)); return; } if(apng.bpp != 4) { - logError("the cursor png must have 4 channels"); + g_logger.error("the cursor png must have 4 channels"); free_apng(&apng); return; } if(apng.width != 32|| apng.height != 32) { - logError("the cursor png must have 32x32 dimension"); + g_logger.error("the cursor png must have 32x32 dimension"); free_apng(&apng); return; } @@ -774,7 +774,7 @@ void WIN32Window::setIcon(const std::string& pngIcon) g_resources.loadFile(pngIcon, fin); if(load_apng(fin, &apng) == 0) { if(apng.bpp != 4) { - logError("could not set app icon, icon image must have 4 channels"); + g_logger.error("could not set app icon, icon image must have 4 channels"); free_apng(&apng); } @@ -807,7 +807,7 @@ void WIN32Window::setIcon(const std::string& pngIcon) free_apng(&apng); } else - logError("could not load app icon"); + g_logger.error("could not load app icon"); } void WIN32Window::setClipboardText(const std::string& text) diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index 7c659d2b..c28a5c92 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -253,7 +253,7 @@ void X11Window::internalOpenDisplay() { m_display = XOpenDisplay(NULL); if(!m_display) - logFatal("Unable to open X11 display"); + g_logger.fatal("Unable to open X11 display"); m_screen = DefaultScreen(m_display); } @@ -295,7 +295,7 @@ void X11Window::internalCreateWindow() m_visible = true; if(!m_window) - logFatal("Unable to create X11 window!"); + g_logger.fatal("Unable to create X11 window!"); // ensure window input focus XWMHints hints; @@ -311,7 +311,7 @@ void X11Window::internalCreateWindow() XSetWMProtocols(m_display, m_window, &m_wmDelete , 1); if(!internalSetupWindowInput()) - logWarning("Input of special keys may be messed up, because window input initialization failed"); + g_logger.warning("Input of special keys may be messed up, because window input initialization failed"); internalConnectGLContext(); } @@ -327,20 +327,20 @@ bool X11Window::internalSetupWindowInput() // create input context (to have better key input handling) if(!XSupportsLocale()) { - logError("X11 doesn't support the current locale"); + g_logger.error("X11 doesn't support the current locale"); return false; } XSetLocaleModifiers(""); m_xim = XOpenIM(m_display, NULL, NULL, NULL); if(!m_xim) { - logError("XOpenIM failed"); + g_logger.error("XOpenIM failed"); return false; } m_xic = XCreateIC(m_xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, m_window, NULL); if(!m_xic) { - logError("Unable to create the input context"); + g_logger.error("Unable to create the input context"); return false; } @@ -352,13 +352,13 @@ void X11Window::internalCheckGL() #ifdef OPENGL_ES m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)m_display); if(m_eglDisplay == EGL_NO_DISPLAY) - logFatal("EGL not supported"); + g_logger.fatal("EGL not supported"); if(!eglInitialize(m_eglDisplay, NULL, NULL)) - logFatal("Unable to initialize EGL"); + g_logger.fatal("Unable to initialize EGL"); #else if(!glXQueryExtension(m_display, NULL, NULL)) - logFatal("GLX not supported"); + g_logger.fatal("GLX not supported"); #endif } @@ -377,10 +377,10 @@ void X11Window::internalChooseGLVisual() EGLint numConfig; if(!eglChooseConfig(m_eglDisplay, attrList, &m_eglConfig, 1, &numConfig)) - logFatal("Failed to choose EGL config"); + g_logger.fatal("Failed to choose EGL config"); if(numConfig != 1) - logWarning("Didn't got the exact EGL config"); + g_logger.warning("Didn't got the exact EGL config"); m_rootWindow = DefaultRootWindow(m_display); #else @@ -394,11 +394,11 @@ void X11Window::internalChooseGLVisual() int nelements; m_fbConfig = glXChooseFBConfig(m_display, m_screen, attrList, &nelements); if(!m_fbConfig) - logFatal("Couldn't choose RGBA, double buffered fbconfig"); + g_logger.fatal("Couldn't choose RGBA, double buffered fbconfig"); m_visual = glXGetVisualFromFBConfig(m_display, *m_fbConfig); if(!m_visual) - logFatal("Couldn't choose RGBA, double buffered visual"); + g_logger.fatal("Couldn't choose RGBA, double buffered visual"); m_rootWindow = RootWindow(m_display, m_visual->screen); #endif @@ -418,15 +418,15 @@ void X11Window::internalCreateGLContext() m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, attrList); if(m_eglContext == EGL_NO_CONTEXT ) - logFatal("Unable to create EGL context: %s", eglGetError()); + g_logger.fatal("Unable to create EGL context: %s", eglGetError()); #else m_glxContext = glXCreateContext(m_display, m_visual, NULL, True); if(!m_glxContext) - logFatal("Unable to create GLX context"); + g_logger.fatal("Unable to create GLX context"); if(!glXIsDirect(m_display, m_glxContext)) - logWarning("GL direct rendering is not possible"); + g_logger.warning("GL direct rendering is not possible"); #endif } @@ -459,12 +459,12 @@ void X11Window::internalConnectGLContext() #ifdef OPENGL_ES m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_window, NULL); if(m_eglSurface == EGL_NO_SURFACE) - logFatal("Unable to create EGL surface: %s", eglGetError()); + g_logger.fatal("Unable to create EGL surface: %s", eglGetError()); if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext)) - logFatal("Unable to connect EGL context into X11 window"); + g_logger.fatal("Unable to connect EGL context into X11 window"); #else if(!glXMakeCurrent(m_display, m_window, m_glxContext)) - logFatal("Unable to set GLX context on X11 window"); + g_logger.fatal("Unable to set GLX context on X11 window"); #endif } @@ -712,7 +712,7 @@ void X11Window::poll() break; std::string text = buf; - //logDebug("char: ", buf[0], " code: ", (int)((uchar)buf[0])); + //g_logger.debug("char: ", buf[0], " code: ", (int)((uchar)buf[0])); if(m_onInputEvent && text.length() > 0) { m_inputEvent.reset(Fw::KeyTextInputEvent); @@ -843,18 +843,18 @@ void X11Window::setMouseCursor(const std::string& file, const Point& hotSpot) apng_data apng; if(load_apng(fin, &apng) != 0) { - logTraceError("unable to load png file %s", file); + g_logger.traceError(stdext::format("unable to load png file %s", file)); return; } if(apng.bpp != 4) { - logError("the cursor png must have 4 channels"); + g_logger.error("the cursor png must have 4 channels"); free_apng(&apng); return; } if(apng.width != 32|| apng.height != 32) { - logError("the cursor png must have 32x32 dimension"); + g_logger.error("the cursor png must have 32x32 dimension"); free_apng(&apng); return; } @@ -961,12 +961,12 @@ void X11Window::setIcon(const std::string& iconFile) apng_data apng; if(load_apng(fin, &apng) != 0) { - logError("Unable to load window icon"); + g_logger.error("Unable to load window icon"); return; } if(apng.bpp != 4) { - logError("Could not set window icon, icon image must have 4 channels"); + g_logger.error("Could not set window icon, icon image must have 4 channels"); free_apng(&apng); return; } @@ -985,7 +985,7 @@ void X11Window::setIcon(const std::string& iconFile) Atom property = XInternAtom(m_display, "_NET_WM_ICON", 0); if(!XChangeProperty(m_display, m_window, property, XA_CARDINAL, 32, PropModeReplace, (const unsigned char*)&iconData[0], iconData.size())) - logError("Couldn't set app icon"); + g_logger.error("Couldn't set app icon"); free_apng(&apng); } diff --git a/src/framework/sound/oggsoundfile.cpp b/src/framework/sound/oggsoundfile.cpp index 9f81b683..30ef4978 100644 --- a/src/framework/sound/oggsoundfile.cpp +++ b/src/framework/sound/oggsoundfile.cpp @@ -39,7 +39,7 @@ bool OggSoundFile::prepareOgg() vorbis_info* vi = ov_info(&m_vorbisFile, -1); if(!vi) { - logError("ogg file not supported: %s", m_file->name()); + g_logger.error(stdext::format("ogg file not supported: %s", m_file->name())); return false; } diff --git a/src/framework/sound/soundbuffer.cpp b/src/framework/sound/soundbuffer.cpp index 92120c2d..249972d7 100644 --- a/src/framework/sound/soundbuffer.cpp +++ b/src/framework/sound/soundbuffer.cpp @@ -40,14 +40,14 @@ bool SoundBuffer::fillBuffer(const SoundFilePtr& soundFile) { ALenum format = soundFile->getSampleFormat(); if(format == AL_UNDETERMINED) { - logError("unable to determine sample format for '%s'", soundFile->getName()); + g_logger.error(stdext::format("unable to determine sample format for '%s'", soundFile->getName())); return false; } DataBuffer samples(soundFile->getSize()); int read = soundFile->read(&samples[0], soundFile->getSize()); if(read <= 0) { - logError("unable to fill audio buffer data for '%s'", soundFile->getName()); + g_logger.error(stdext::format("unable to fill audio buffer data for '%s'", soundFile->getName())); return false; } @@ -59,7 +59,7 @@ bool SoundBuffer::fillBuffer(ALenum sampleFormat, const DataBuffer& data, alBufferData(m_bufferId, sampleFormat, &data[0], size, rate); ALenum err = alGetError(); if(err != AL_NO_ERROR) { - logError("unable to fill audio buffer data: %s", alGetString(err)); + g_logger.error(stdext::format("unable to fill audio buffer data: %s", alGetString(err))); return false; } return true; diff --git a/src/framework/sound/soundfile.cpp b/src/framework/sound/soundfile.cpp index 10f87a22..c22f6f8e 100644 --- a/src/framework/sound/soundfile.cpp +++ b/src/framework/sound/soundfile.cpp @@ -33,7 +33,7 @@ SoundFilePtr SoundFile::loadSoundFile(const std::string& filename) { FileStreamPtr file = g_resources.openFile(filename); if(!file) { - logTraceError("unable to open %s", filename); + g_logger.traceError(stdext::format("unable to open %s", filename)); return nullptr; } @@ -50,7 +50,7 @@ SoundFilePtr SoundFile::loadSoundFile(const std::string& filename) if(oggSoundFile->prepareOgg()) soundFile = oggSoundFile; } else - logError("unknown sound file format %s", filename); + g_logger.error(stdext::format("unknown sound file format %s", filename)); return soundFile; } diff --git a/src/framework/sound/soundmanager.cpp b/src/framework/sound/soundmanager.cpp index cb49cc33..dd15f444 100644 --- a/src/framework/sound/soundmanager.cpp +++ b/src/framework/sound/soundmanager.cpp @@ -36,13 +36,13 @@ void SoundManager::init() { m_device = alcOpenDevice(NULL); if(!m_device) { - logError("unable to open audio device"); + g_logger.error("unable to open audio device"); return; } m_context = alcCreateContext(m_device, NULL); if(!m_context) { - logError("unable to create audio context: %s", alcGetString(m_device, alcGetError(m_device))); + g_logger.error(stdext::format("unable to create audio context: %s", alcGetString(m_device, alcGetError(m_device)))); return; } alcMakeContextCurrent(m_context); @@ -136,7 +136,7 @@ void SoundManager::play(const std::string& filename) SoundSourcePtr soundSource = createSoundSource(filename); if(!soundSource) { - logError("unable to play '%s'", filename); + g_logger.error(stdext::format("unable to play '%s'", filename)); return; } @@ -175,7 +175,7 @@ void SoundManager::playMusic(const std::string& filename, float fadetime) m_musicSource = createSoundSource(filename); if(!m_musicSource) { - logError("unable to play '%s'", filename); + g_logger.error(stdext::format("unable to play '%s'", filename)); return; } @@ -218,7 +218,7 @@ SoundSourcePtr SoundManager::createSoundSource(const std::string& filename) buffer->fillBuffer(soundFile); source->setBuffer(buffer); m_buffers[filename] = buffer; - logWarning("uncached sound '%s' requested to be played", filename); + g_logger.warning(stdext::format("uncached sound '%s' requested to be played", filename)); } else { StreamSoundSourcePtr streamSource(new StreamSoundSource); streamSource->setSoundFile(soundFile); diff --git a/src/framework/sound/streamsoundsource.cpp b/src/framework/sound/streamsoundsource.cpp index 64bd7402..de401064 100644 --- a/src/framework/sound/streamsoundsource.cpp +++ b/src/framework/sound/streamsoundsource.cpp @@ -46,7 +46,7 @@ void StreamSoundSource::setSoundFile(const SoundFilePtr& soundFile) void StreamSoundSource::play() { if(!m_soundFile) { - logError("there is not sound file to play the stream"); + g_logger.error("there is not sound file to play the stream"); return; } @@ -100,7 +100,7 @@ void StreamSoundSource::update() if(processed == 0 || !m_looping) return; - logTraceError("restarting audio source because of buffer underrun"); + g_logger.traceError("restarting audio source because of buffer underrun"); play(); } } @@ -143,12 +143,12 @@ bool StreamSoundSource::fillBufferAndQueue(ALuint buffer) alBufferData(buffer, format, &bufferData[0], bytesRead, m_soundFile->getRate()); ALenum err = alGetError(); if(err != AL_NO_ERROR) - logError("unable to refill audio buffer for '%s': %s", m_soundFile->getName(), alGetString(err)); + g_logger.error(stdext::format("unable to refill audio buffer for '%s': %s", m_soundFile->getName(), alGetString(err))); alSourceQueueBuffers(m_sourceId, 1, &buffer); err = alGetError(); if(err != AL_NO_ERROR) - logError("unable to queue audio buffer for '%s': %s", m_soundFile->getName(), alGetString(err)); + g_logger.error(stdext::format("unable to queue audio buffer for '%s': %s", m_soundFile->getName(), alGetString(err))); } // return false if there aren't more buffers to fill @@ -158,12 +158,12 @@ bool StreamSoundSource::fillBufferAndQueue(ALuint buffer) void StreamSoundSource::downMix(StreamSoundSource::DownMix downMix) { if(!m_soundFile) { - logError("down mix must be set after setting a sound file"); + g_logger.error("down mix must be set after setting a sound file"); return; } if(m_soundFile->getSampleFormat() != AL_FORMAT_STEREO16) { - logError("can only downmix 16 bit stereo audio files"); + g_logger.error("can only downmix 16 bit stereo audio files"); return; } diff --git a/src/framework/ui/uianchorlayout.cpp b/src/framework/ui/uianchorlayout.cpp index 534fe457..e4cef72a 100644 --- a/src/framework/ui/uianchorlayout.cpp +++ b/src/framework/ui/uianchorlayout.cpp @@ -93,7 +93,7 @@ bool UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch return false; if(first == widget) { - logError("child '%s' of parent widget '%s' is recursively anchored to itself, please fix this", widget->getId(), parentWidget->getId()); + g_logger.error(stdext::format("child '%s' of parent widget '%s' is recursively anchored to itself, please fix this", widget->getId(), parentWidget->getId())); return false; } diff --git a/src/framework/ui/uiframecounter.h b/src/framework/ui/uiframecounter.h deleted file mode 100644 index a7ca06af..00000000 --- a/src/framework/ui/uiframecounter.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2010-2012 OTClient - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef UIFRAMECOUNTER_H -#define UIFRAMECOUNTER_H - -#include "uiwidget.h" - -class UIFrameCounter : public UIWidget -{ -public: - UIFrameCounter(); - void drawSelf(); - - void setAlign(Fw::AlignmentFlag align) { m_align = align; } - Fw::AlignmentFlag getAlign() { return m_align; } - int getFrameCount() { return m_frameCount; } - -protected: - virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); - -private: - Fw::AlignmentFlag m_align; - int m_frameCount; - ticks_t m_lastFrameTicks; - std::string m_fpsText; -}; - -#endif diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index 7e67c3b2..a7ed64bf 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -286,7 +286,7 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget) g_lua.collectGarbage(); for(const UIWidgetPtr& widget : backupList) { if(widget->getUseCount() != 1) - logWarning("widget '%s' destroyed but still have %d reference(s) left", widget->getId(), widget->getUseCount()-1); + g_logger.warning(stdext::format("widget '%s' destroyed but still have %d reference(s) left", widget->getId(), widget->getUseCount()-1)); } }, 1); }, 1000); @@ -302,7 +302,7 @@ bool UIManager::importStyle(const std::string& file) importStyleFromOTML(styleNode); return true; } catch(stdext::exception& e) { - logError("Failed to import UI styles from '%s': %s", file, e.what()); + g_logger.error(stdext::format("Failed to import UI styles from '%s': %s", file, e.what())); return false; } } @@ -326,7 +326,7 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode) /* auto it = m_styles.find(name); if(it != m_styles.end()) - logWarning("style '%s' is being redefined", name); + g_logger.warning("style '%s' is being redefined", name); */ OTMLNodePtr originalStyle = getStyle(base); @@ -383,7 +383,7 @@ UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent return widget; } catch(stdext::exception& e) { - logError("failed to load UI from '%s': %s", file, e.what()); + g_logger.error(stdext::format("failed to load UI from '%s': %s", file, e.what())); return nullptr; } } @@ -394,7 +394,7 @@ UIWidgetPtr UIManager::createWidgetFromStyle(const std::string& styleName, const try { return createWidgetFromOTML(node, parent); } catch(stdext::exception& e) { - logError("failed to create widget from style '%s': %s", styleName, e.what()); + g_logger.error(stdext::format("failed to create widget from style '%s': %s", styleName, e.what())); return nullptr; } } diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 61d99471..f9f9e24f 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -48,7 +48,7 @@ UIWidget::~UIWidget() { #ifdef DEBUG if(!m_destroyed) - logWarning("widget '%s' was not explicitly destroyed", m_id); + g_logger.warning(stdext::format("widget '%s' was not explicitly destroyed", m_id)); #endif } @@ -123,17 +123,17 @@ void UIWidget::drawChildren(const Rect& visibleRect, bool foregroundPane) void UIWidget::addChild(const UIWidgetPtr& child) { if(!child) { - logWarning("attempt to add a null child into a UIWidget"); + g_logger.warning("attempt to add a null child into a UIWidget"); return; } if(child->isDestroyed()) { - logWarning("attemp to add a destroyed child into a UIWidget"); + g_logger.warning("attemp to add a destroyed child into a UIWidget"); return; } if(hasChild(child)) { - logWarning("attempt to add a child again into a UIWidget"); + g_logger.warning("attempt to add a child again into a UIWidget"); return; } @@ -164,19 +164,19 @@ void UIWidget::addChild(const UIWidgetPtr& child) void UIWidget::insertChild(int index, const UIWidgetPtr& child) { if(!child) { - logWarning("attempt to insert a null child into a UIWidget"); + g_logger.warning("attempt to insert a null child into a UIWidget"); return; } if(hasChild(child)) { - logWarning("attempt to insert a child again into a UIWidget"); + g_logger.warning("attempt to insert a child again into a UIWidget"); return; } index = index <= 0 ? (m_children.size() + index) : index-1; if(!(index >= 0 && (uint)index <= m_children.size())) { - logTraceError("attemp to insert a child in an invalid index"); + g_logger.traceError("attemp to insert a child in an invalid index"); return; } @@ -231,7 +231,7 @@ void UIWidget::removeChild(UIWidgetPtr child) g_ui.onWidgetDisappear(child); } else - logError("attempt to remove an unknown child from a UIWidget"); + g_logger.error("attempt to remove an unknown child from a UIWidget"); } @@ -244,7 +244,7 @@ void UIWidget::focusChild(const UIWidgetPtr& child, Fw::FocusReason reason) return; if(child && !hasChild(child)) { - logError("attempt to focus an unknown child in a UIWidget"); + g_logger.error("attempt to focus an unknown child in a UIWidget"); return; } @@ -338,7 +338,7 @@ void UIWidget::lowerChild(UIWidgetPtr child) // remove and push child again auto it = std::find(m_children.begin(), m_children.end(), child); if(it == m_children.end()) { - logTraceError("cannot find child"); + g_logger.traceError("cannot find child"); return; } @@ -358,7 +358,7 @@ void UIWidget::raiseChild(UIWidgetPtr child) // remove and push child again auto it = std::find(m_children.begin(), m_children.end(), child); if(it == m_children.end()) { - logTraceError("cannot find child"); + g_logger.traceError("cannot find child"); return; } m_children.erase(it); @@ -377,7 +377,7 @@ void UIWidget::moveChildToIndex(const UIWidgetPtr& child, int index) // remove and push child again auto it = std::find(m_children.begin(), m_children.end(), child); if(it == m_children.end()) { - logTraceError("cannot find child"); + g_logger.traceError("cannot find child"); return; } m_children.erase(it); @@ -394,7 +394,7 @@ void UIWidget::lockChild(const UIWidgetPtr& child) return; if(!hasChild(child)) { - logTraceError("cannot find child"); + g_logger.traceError("cannot find child"); return; } @@ -426,7 +426,7 @@ void UIWidget::unlockChild(const UIWidgetPtr& child) return; if(!hasChild(child)) { - logTraceError("cannot find child"); + g_logger.traceError("cannot find child"); return; } @@ -504,7 +504,7 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode) } m_firstOnStyle = false; } catch(stdext::exception& e) { - logError("failed to apply style to widget '%s': %s", m_id, e.what()); + g_logger.error(stdext::format("failed to apply style to widget '%s': %s", m_id, e.what())); } m_loadingStyle = false; } @@ -517,7 +517,7 @@ void UIWidget::addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedW if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout()) anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge); else - logError("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id); + g_logger.error(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id)); } void UIWidget::removeAnchor(Fw::AnchorEdge anchoredEdge) @@ -534,7 +534,7 @@ void UIWidget::centerIn(const std::string& hookedWidgetId) anchorLayout->addAnchor(asUIWidget(), Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter); anchorLayout->addAnchor(asUIWidget(), Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter); } else - logError("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id); + g_logger.error(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id)); } void UIWidget::fill(const std::string& hookedWidgetId) @@ -548,7 +548,7 @@ void UIWidget::fill(const std::string& hookedWidgetId) anchorLayout->addAnchor(asUIWidget(), Fw::AnchorTop, hookedWidgetId, Fw::AnchorTop); anchorLayout->addAnchor(asUIWidget(), Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom); } else - logError("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id); + g_logger.error(stdext::format("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id)); } void UIWidget::breakAnchors() @@ -714,7 +714,7 @@ void UIWidget::internalDestroy() void UIWidget::destroy() { if(m_destroyed) - logWarning("attempt to destroy widget '%s' two times", m_id); + g_logger.warning(stdext::format("attempt to destroy widget '%s' two times", m_id)); // hold itself reference UIWidgetPtr self = asUIWidget(); @@ -803,7 +803,7 @@ void UIWidget::setLayout(const UILayoutPtr& layout) bool UIWidget::setRect(const Rect& rect) { if(rect.width() > 8192 || rect.height() > 8192) { - logError("attempt to set huge rect size (%s) for %s", stdext::to_string(rect), m_id); + g_logger.error(stdext::format("attempt to set huge rect size (%s) for %s", stdext::to_string(rect), m_id)); return false; } // only update if the rect really changed @@ -835,7 +835,7 @@ void UIWidget::setStyle(const std::string& styleName) { OTMLNodePtr styleNode = g_ui.getStyle(styleName); if(!styleNode) { - logTraceError("unable to retrieve style '%s': not a defined style", styleName); + g_logger.traceError(stdext::format("unable to retrieve style '%s': not a defined style", styleName)); return; } styleNode = styleNode->clone(); diff --git a/src/otclient/core/container.cpp b/src/otclient/core/container.cpp index f21080c3..7ccf084e 100644 --- a/src/otclient/core/container.cpp +++ b/src/otclient/core/container.cpp @@ -59,7 +59,7 @@ void Container::addItems(const std::vector& items) void Container::updateItem(int slot, const ItemPtr& item) { if(slot < 0 || slot >= (int)m_items.size()) { - logTraceError("slot not found"); + g_logger.traceError("slot not found"); return; } @@ -73,7 +73,7 @@ void Container::updateItem(int slot, const ItemPtr& item) void Container::removeItem(int slot) { if(slot < 0 || slot >= (int)m_items.size()) { - logTraceError("slot not found"); + g_logger.traceError("slot not found"); return; } diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 3a637e88..ff5fdac2 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -193,7 +193,7 @@ void Game::processCloseContainer(int containerId) { ContainerPtr container = getContainer(containerId); if(!container) { - logTraceError("container not found"); + g_logger.traceError("container not found"); return; } @@ -205,7 +205,7 @@ void Game::processContainerAddItem(int containerId, const ItemPtr& item) { ContainerPtr container = getContainer(containerId); if(!container) { - logTraceError("container not found"); + g_logger.traceError("container not found"); return; } @@ -216,7 +216,7 @@ void Game::processContainerUpdateItem(int containerId, int slot, const ItemPtr& { ContainerPtr container = getContainer(containerId); if(!container) { - logTraceError("container not found"); + g_logger.traceError("container not found"); return; } @@ -227,7 +227,7 @@ void Game::processContainerRemoveItem(int containerId, int slot) { ContainerPtr container = getContainer(containerId); if(!container) { - logTraceError("container not found"); + g_logger.traceError("container not found"); return; } @@ -398,7 +398,7 @@ void Game::processWalkCancel(Otc::Direction direction) void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldName, const std::string& worldHost, int worldPort, const std::string& characterName) { if(m_protocolGame || isOnline()) { - logTraceError("unable to login into a world while already online or logging"); + g_logger.traceError("unable to login into a world while already online or logging"); return; } @@ -1002,7 +1002,7 @@ bool Game::checkBotProtection() // accepts calls comming from a stacktrace containing only C++ functions, // if the stacktrace contains a lua function, then only accept if the engine is processing an input event if(g_lua.isInCppCallback() && !g_app->isOnInputEvent() && m_denyBotCall) { - logError(g_lua.traceback("caught a lua call to a bot protected game function, the call was canceled")); + g_logger.error(g_lua.traceback("caught a lua call to a bot protected game function, the call was canceled")); return false; } return true; @@ -1022,7 +1022,7 @@ bool Game::canPerformGameAction() void Game::setClientVersion(int clientVersion) { if(isOnline()) { - logError("Unable to change client version while online"); + g_logger.error("Unable to change client version while online"); return; } diff --git a/src/otclient/core/item.cpp b/src/otclient/core/item.cpp index 1ad48520..bd24f3cd 100644 --- a/src/otclient/core/item.cpp +++ b/src/otclient/core/item.cpp @@ -41,7 +41,7 @@ ItemPtr Item::create(int id) { ItemPtr item = ItemPtr(new Item); if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid()) - logTraceError("invalid item id %d", id); + g_logger.traceError(stdext::format("invalid item id %d", id)); else { item->setId(id); } @@ -190,7 +190,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate) void Item::setId(uint32 id) { if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid()) { - logTraceError("invalid item id %d", id); + g_logger.traceError(stdext::format("invalid item id %d", id)); return; } m_id = id; diff --git a/src/otclient/core/mapview.cpp b/src/otclient/core/mapview.cpp index c5e594d2..1c66a093 100644 --- a/src/otclient/core/mapview.cpp +++ b/src/otclient/core/mapview.cpp @@ -413,7 +413,7 @@ void MapView::updateGeometry(const Size& visibleDimension, const Size& optimized } if(tileSize == 0) { - logTraceError("reached max zoom out"); + g_logger.traceError("reached max zoom out"); return; } @@ -478,12 +478,12 @@ void MapView::setVisibleDimension(const Size& visibleDimension) return; if(visibleDimension.width() % 2 != 1 || visibleDimension.height() % 2 != 1) { - logTraceError("visible dimension must be odd"); + g_logger.traceError("visible dimension must be odd"); return; } if(visibleDimension < Size(3,3)) { - logTraceError("reach max zoom in"); + g_logger.traceError("reach max zoom in"); return; } diff --git a/src/otclient/core/spritemanager.cpp b/src/otclient/core/spritemanager.cpp index 5ffffcad..3c4c15d4 100644 --- a/src/otclient/core/spritemanager.cpp +++ b/src/otclient/core/spritemanager.cpp @@ -48,7 +48,7 @@ bool SpriteManager::load(const std::string& file) m_loaded = true; return true; } catch(stdext::exception& e) { - logError("Failed to load sprites from '%s': %s", file, e.what()); + g_logger.error(stdext::format("Failed to load sprites from '%s': %s", file, e.what())); return false; } } @@ -98,7 +98,7 @@ ImagePtr SpriteManager::getSpriteImage(int id) uint16 coloredPixels = m_spritesFile->getU16(); if(writePos + transparentPixels*4 + coloredPixels*3 >= SPRITE_DATA_SIZE) { - logWarning("corrupt sprite id %d", id); + g_logger.warning(stdext::format("corrupt sprite id %d", id)); return nullptr; } diff --git a/src/otclient/core/statictext.cpp b/src/otclient/core/statictext.cpp index 98a07ff6..38fed19d 100644 --- a/src/otclient/core/statictext.cpp +++ b/src/otclient/core/statictext.cpp @@ -106,7 +106,7 @@ void StaticText::compose() text += " says:\n"; m_color = Color(95, 247, 247); } else { - logWarning("Unknown speak type: %d", m_messageType); + g_logger.warning(stdext::format("Unknown speak type: %d", m_messageType)); } for(uint i = 0; i < m_messages.size(); ++i) { diff --git a/src/otclient/core/thing.cpp b/src/otclient/core/thing.cpp index 9fb00c54..56fe81a7 100644 --- a/src/otclient/core/thing.cpp +++ b/src/otclient/core/thing.cpp @@ -70,7 +70,7 @@ int Thing::getStackpos() else if(const TilePtr& tile = getTile()) return tile->getThingStackpos(asThing()); else { - logTraceError("got a thing with invalid stackpos"); + g_logger.traceError("got a thing with invalid stackpos"); return -1; } } diff --git a/src/otclient/core/thingstype.cpp b/src/otclient/core/thingstype.cpp index 1fea99ab..1cf8b3e8 100644 --- a/src/otclient/core/thingstype.cpp +++ b/src/otclient/core/thingstype.cpp @@ -33,7 +33,7 @@ bool ThingsType::load(const std::string& file) { FileStreamPtr fin = g_resources.openFile(file); if(!fin) { - logError("unable to open dat file '%s'", file); + g_logger.error(stdext::format("unable to open dat file '%s'", file)); return false; } @@ -50,7 +50,7 @@ bool ThingsType::load(const std::string& file) for(int id = 0; id < numThings[i]; ++id) { m_things[i][id].m_category = i; if(!parseThingType(fin, m_things[i][id])) { - logError("corrupt or dat file"); + g_logger.error("corrupt or dat file"); return false; } } diff --git a/src/otclient/net/protocolcodes.h b/src/otclient/net/protocolcodes.h index f9159dc8..f6d04f7e 100644 --- a/src/otclient/net/protocolcodes.h +++ b/src/otclient/net/protocolcodes.h @@ -475,7 +475,7 @@ namespace Proto { case Proto::ServerSpeakBroadcast: return Otc::SpeakBroadcast; case Proto::ServerSpeakPrivateRedTo: return Otc::SpeakPrivateRed; default: - logError("unknown protocol speak type %d", type); + g_logger.error(stdext::format("unknown protocol speak type %d", type)); return Otc::SpeakSay; } } @@ -497,7 +497,7 @@ namespace Proto { case Otc::SpeakMonsterSay: return Proto::ServerSpeakMonsterSay; case Otc::SpeakMonsterYell: return Proto::ServerSpeakMonsterYell; default: - logError("unknown protocol speak type desc %d", type); + g_logger.error(stdext::format("unknown protocol speak type desc %d", type)); return Proto::ServerSpeakSay; } } @@ -515,7 +515,7 @@ namespace Proto { case Proto::MessageConsoleBlue: return "consoleBlue"; case Proto::MessageConsoleRed: return "consoleRed"; default: - logError("unknown protocol text message type %d", type); + g_logger.error(stdext::format("unknown protocol text message type %d", type)); return "unknown"; } } diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index ed58c537..cd8ff487 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -47,7 +47,7 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) continue; if(!m_gameInitialized && opcode > Proto::GameServerFirstGameOpcode) - logWarning("received a game opcode from the server, but the game is not initialized yet, this is a server side bug"); + g_logger.warning("received a game opcode from the server, but the game is not initialized yet, this is a server side bug"); switch(opcode) { case Proto::GameServerInitGame: @@ -319,8 +319,8 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) prevOpcode = opcode; } } catch(stdext::exception& e) { - logError("Network exception (%d bytes unread, last opcode is %d, prev opcode is %d): %s", - msg->getUnreadSize(), opcode, prevOpcode, e.what()); + g_logger.error(stdext::format("Network exception (%d bytes unread, last opcode is %d, prev opcode is %d): %s", + msg->getUnreadSize(), opcode, prevOpcode, e.what())); } } @@ -476,7 +476,7 @@ void ProtocolGame::parseTileTransformThing(const InputMessagePtr& msg) ThingPtr thing = getThing(msg); if(thing) { if(!g_map.removeThingByPos(pos, stackPos)) - logTraceError("could not remove thing"); + g_logger.traceError("could not remove thing"); g_map.addThing(thing, pos, stackPos); } } @@ -487,7 +487,7 @@ void ProtocolGame::parseTileRemoveThing(const InputMessagePtr& msg) int stackPos = msg->getU8(); if(!g_map.removeThingByPos(pos, stackPos)) - logTraceError("could not remove thing"); + g_logger.traceError("could not remove thing"); } void ProtocolGame::parseCreatureMove(const InputMessagePtr& msg) @@ -498,19 +498,19 @@ void ProtocolGame::parseCreatureMove(const InputMessagePtr& msg) ThingPtr thing = g_map.getThing(oldPos, oldStackpos); if(!thing) { - logTraceError("could not get thing"); + g_logger.traceError("could not get thing"); return; } CreaturePtr creature = thing->asCreature(); if(!creature) { - logTraceError("thing is not a creature"); + g_logger.traceError("thing is not a creature"); return; } // update map tiles if(!g_map.removeThing(thing)) - logTraceError("could not remove thing"); + g_logger.traceError("could not remove thing"); g_map.addThing(thing, newPos); } @@ -699,7 +699,7 @@ void ProtocolGame::parseCreatureMark(const InputMessagePtr& msg) if(creature) creature->addTimedSquare(color); else - logTraceError("could not get creature"); + g_logger.traceError("could not get creature"); } void ProtocolGame::parseTrappers(const InputMessagePtr& msg) @@ -707,7 +707,7 @@ void ProtocolGame::parseTrappers(const InputMessagePtr& msg) int numTrappers = msg->getU8(); if(numTrappers > 8) - logTraceError("too many trappers"); + g_logger.traceError("too many trappers"); for(int i=0;igetU32(); @@ -715,7 +715,7 @@ void ProtocolGame::parseTrappers(const InputMessagePtr& msg) if(creature) { //TODO: set creature as trapper } else - logTraceError("could not get creature"); + g_logger.traceError("could not get creature"); } } @@ -728,7 +728,7 @@ void ProtocolGame::parseCreatureHealth(const InputMessagePtr& msg) if(creature) creature->setHealthPercent(healthPercent); else - logTraceError("could not get creature"); + g_logger.traceError("could not get creature"); } void ProtocolGame::parseCreatureLight(const InputMessagePtr& msg) @@ -743,7 +743,7 @@ void ProtocolGame::parseCreatureLight(const InputMessagePtr& msg) if(creature) creature->setLight(light); else - logTraceError("could not get creature"); + g_logger.traceError("could not get creature"); } void ProtocolGame::parseCreatureOutfit(const InputMessagePtr& msg) @@ -755,7 +755,7 @@ void ProtocolGame::parseCreatureOutfit(const InputMessagePtr& msg) if(creature) creature->setOutfit(outfit); else - logTraceError("could not get creature"); + g_logger.traceError("could not get creature"); } void ProtocolGame::parseCreatureSpeed(const InputMessagePtr& msg) @@ -767,7 +767,7 @@ void ProtocolGame::parseCreatureSpeed(const InputMessagePtr& msg) if(creature) creature->setSpeed(speed); else - logTraceError("could not get creature"); + g_logger.traceError("could not get creature"); } void ProtocolGame::parseCreatureSkulls(const InputMessagePtr& msg) @@ -779,7 +779,7 @@ void ProtocolGame::parseCreatureSkulls(const InputMessagePtr& msg) if(creature) creature->setSkull(skull); else - logTraceError("could not get creature"); + g_logger.traceError("could not get creature"); } void ProtocolGame::parseCreatureShields(const InputMessagePtr& msg) @@ -791,7 +791,7 @@ void ProtocolGame::parseCreatureShields(const InputMessagePtr& msg) if(creature) creature->setShield(shield); else - logTraceError("could not get creature"); + g_logger.traceError("could not get creature"); } void ProtocolGame::parseCreatureUnpass(const InputMessagePtr& msg) @@ -803,7 +803,7 @@ void ProtocolGame::parseCreatureUnpass(const InputMessagePtr& msg) if(creature) creature->setPassable(!unpass); else - logTraceError("could not get creature"); + g_logger.traceError("could not get creature"); } void ProtocolGame::parseEditText(const InputMessagePtr& msg) @@ -1238,7 +1238,7 @@ void ProtocolGame::parseExtendedOpcode(const InputMessagePtr& msg) try { callLuaField("onExtendedOpcode", opcode, buffer); } catch(stdext::exception& e) { - logError("Network exception in extended opcode %d: %s", opcode, e.what()); + g_logger.error(stdext::format("Network exception in extended opcode %d: %s", opcode, e.what())); } } } @@ -1304,7 +1304,7 @@ void ProtocolGame::setTileDescription(const InputMessagePtr& msg, Position posit } else { if(stackPos >= 10) - logTraceError("too many things, stackpos=%d, pos=%s", stackPos, stdext::to_string(position)); + g_logger.traceError(stdext::format("too many things, stackpos=%d, pos=%s", stackPos, stdext::to_string(position))); ThingPtr thing = getThing(msg); g_map.addThing(thing, position, -1); @@ -1380,7 +1380,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) uint id = msg->getU32(); creature = g_map.getCreatureById(id); if(!creature) - logTraceError("server said that a creature is known, but it's not"); + g_logger.traceError("server said that a creature is known, but it's not"); } else { uint removeId = msg->getU32(); g_map.removeCreatureById(removeId); @@ -1414,7 +1414,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) else if(creatureType == Proto::CreatureTypeNpc) creature = NpcPtr(new Npc); else - logTraceError("creature type is invalid"); + g_logger.traceError("creature type is invalid"); if(creature) { creature->setId(id); @@ -1467,7 +1467,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) creature = g_map.getCreatureById(id); if(!creature) - logTraceError("invalid creature"); + g_logger.traceError("invalid creature"); Otc::Direction direction = (Otc::Direction)msg->getU8(); if(creature) diff --git a/src/otclient/net/protocolgamesend.cpp b/src/otclient/net/protocolgamesend.cpp index e9135776..b1e2efc6 100644 --- a/src/otclient/net/protocolgamesend.cpp +++ b/src/otclient/net/protocolgamesend.cpp @@ -40,7 +40,7 @@ void ProtocolGame::sendExtendedOpcode(uint8 opcode, const std::string& buffer) msg->addString(buffer); safeSend(msg); } else { - logError("Unable to send extended opcode %d, extended opcodes are not enabled", opcode); + g_logger.error(stdext::format("Unable to send extended opcode %d, extended opcodes are not enabled", opcode)); } } diff --git a/src/otclient/net/protocollogin.cpp b/src/otclient/net/protocollogin.cpp index ce5ae156..5fc973f9 100644 --- a/src/otclient/net/protocollogin.cpp +++ b/src/otclient/net/protocollogin.cpp @@ -70,7 +70,7 @@ void ProtocolLogin::onRecv(const InputMessagePtr& msg) } } } catch(stdext::exception& e) { - logTraceError(e.what()); + g_logger.error(stdext::format("Network exception in login protocol: %s", e.what())); } disconnect(); } diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index 445527b6..ebe2536a 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -72,15 +72,15 @@ void OTClient::init(const std::vector& args) } } - logInfo( + g_logger.info(stdext::format( "%s %s (rev %s) built on %s", Otc::AppName, Otc::AppVersion, BUILD_REVISION, - BUILD_DATE); + BUILD_DATE)); if(startupOptions.length() > 0) - logInfo("Startup options: %s", startupOptions); + g_logger.info(stdext::format("Startup options: %s", startupOptions)); g_logger.setLogFile(stdext::format("%s.txt", Otc::AppCompactName)); Application::init(args); @@ -104,7 +104,7 @@ void OTClient::init(const std::vector& args) try { g_lua.runScript("/otclientrc.lua"); } catch(LuaException& e) { - logError("failed to load otclientrc.lua: %s", e.what()); + g_logger.error(stdext::format("failed to load otclientrc.lua: %s", e.what())); } } }