diff --git a/Common/Data/Encoding/Compression.cpp b/Common/Data/Encoding/Compression.cpp index 01bc6a1815..c348ed9313 100644 --- a/Common/Data/Encoding/Compression.cpp +++ b/Common/Data/Encoding/Compression.cpp @@ -4,9 +4,6 @@ #include #include -#include -#include -#include #include #include @@ -48,8 +45,7 @@ bool compress_string(const std::string& str, std::string *dest, int compressionl deflateEnd(&zs); if (ret != Z_STREAM_END) { // an error occurred that was not EOF - std::ostringstream oss; - oss << "Exception during zlib compression: (" << ret << ") " << zs.msg; + ERROR_LOG(Log::IO, "Exception during zlib compression: (%d): %s", ret, zs.msg); return false; } diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index df9587aa3b..d95ad660c3 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -46,6 +46,7 @@ #include "Common/Data/Encoding/Utf8.h" #include "Common/StringUtils.h" #include "Common/TimeUtil.h" +#include "Common/Log/LogManager.h" #include "Core/Config.h" #include "Core/ConfigValues.h" @@ -805,6 +806,8 @@ int main(int argc, char *argv[]) { TimeInit(); + g_logManager.EnableOutput(LogOutput::Stdio); + for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "--version")) { printf("%s\n", PPSSPP_GIT_VERSION); diff --git a/SDL/SDLJoystick.cpp b/SDL/SDLJoystick.cpp index a0d206ee21..94a6f481ba 100644 --- a/SDL/SDLJoystick.cpp +++ b/SDL/SDLJoystick.cpp @@ -1,4 +1,3 @@ -#include #include #include "Common/File/FileUtil.h" @@ -6,6 +5,7 @@ #include "Common/StringUtils.h" #include "Common/System/NativeApp.h" #include "Common/System/System.h" +#include "Common/Log.h" #include "Core/Config.h" #include "Core/KeyMap.h" @@ -13,8 +13,7 @@ using namespace std; -static int SDLJoystickEventHandlerWrapper(void* userdata, SDL_Event* event) -{ +static int SDLJoystickEventHandlerWrapper(void* userdata, SDL_Event* event) { static_cast(userdata)->ProcessInput(*event); return 0; } @@ -26,7 +25,7 @@ SDLJoystick::SDLJoystick(bool init_SDL ) : registeredAsEventHandler(false) { } const char *dbPath = "gamecontrollerdb.txt"; - cout << "loading control pad mappings from " << dbPath << ": "; + INFO_LOG(Log::System, "loading control pad mappings from %s:", dbPath); size_t size; u8 *mappingData = g_VFS.ReadFile(dbPath, &size); @@ -34,13 +33,12 @@ SDLJoystick::SDLJoystick(bool init_SDL ) : registeredAsEventHandler(false) { SDL_RWops *rw = SDL_RWFromConstMem(mappingData, size); // 1 to free the rw after use if (SDL_GameControllerAddMappingsFromRW(rw, 1) == -1) { - cout << "Failed to read mapping data - corrupt?" << endl; + ERROR_LOG(Log::System, "Failed to read mapping data - corrupt?"); } delete[] mappingData; } else { - cout << "gamecontrollerdb.txt missing" << endl; + WARN_LOG(Log::System, "gamecontrollerdb.txt missing?"); } - cout << "SUCCESS!" << endl; setUpControllers(); } @@ -50,7 +48,7 @@ void SDLJoystick::setUpControllers() { setUpController(i); } if (controllers.size() > 0) { - cout << "pad 1 has been assigned to control pad: " << SDL_GameControllerName(controllers.front()) << endl; + INFO_LOG(Log::System, "pad 1 has been assigned to control pad: %s", SDL_GameControllerName(controllers.front())); } } @@ -59,7 +57,7 @@ void SDLJoystick::setUpController(int deviceIndex) { char pszGUID[cbGUID]; if (!SDL_IsGameController(deviceIndex)) { - cout << "Control pad device " << deviceIndex << " not supported by SDL game controller database, attempting to create default mapping..." << endl; + WARN_LOG(Log::System, "Control pad device %d not supported by SDL game controller database, attempting to create default mapping...", deviceIndex); SDL_Joystick *joystick = SDL_JoystickOpen(deviceIndex); if (joystick) { SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), pszGUID, cbGUID); @@ -67,13 +65,13 @@ void SDLJoystick::setUpController(int deviceIndex) { const std::string safeName = ReplaceAll(SDL_JoystickName(joystick), ",", ""); std::string mapping = std::string(pszGUID) + "," + safeName + ",x:b3,a:b0,b:b1,y:b2,back:b8,guide:b10,start:b9,dpleft:b15,dpdown:b14,dpright:b16,dpup:b13,leftshoulder:b4,lefttrigger:a2,rightshoulder:b6,rightshoulder:b5,righttrigger:a5,leftstick:b7,leftstick:b11,rightstick:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4"; if (SDL_GameControllerAddMapping(mapping.c_str()) == 1){ - cout << "Added default mapping ok" << endl; + INFO_LOG(Log::System, "Added default mapping ok"); } else { - cout << "Failed to add default mapping" << endl; + ERROR_LOG(Log::System, "Failed to add default mapping"); } SDL_JoystickClose(joystick); } else { - cout << "Failed to get joystick identifier. Read-only device? Control pad device " + std::to_string(deviceIndex) << endl; + ERROR_LOG(Log::System, "Failed to get joystick identifier. Read-only device? Control pad device %d", deviceIndex); } } else { SDL_Joystick *joystick = SDL_JoystickOpen(deviceIndex); @@ -87,15 +85,14 @@ void SDLJoystick::setUpController(int deviceIndex) { if (SDL_GameControllerGetAttached(controller)) { controllers.push_back(controller); controllerDeviceMap[SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller))] = deviceIndex; - cout << "found control pad: " << SDL_GameControllerName(controller) << ", loading mapping: "; + INFO_LOG(Log::System, "found control pad: %s, loading mapping", SDL_GameControllerName(controller)); // NOTE: The case to InputDeviceID here is wrong, we should do some kind of lookup. KeyMap::NotifyPadConnected((InputDeviceID)deviceIndex, std::string(pszGUID) + ": " + SDL_GameControllerName(controller)); - auto mapping = SDL_GameControllerMapping(controller); - if (mapping == NULL) { - //cout << "FAILED" << endl; - cout << "Could not find mapping in SDL2 controller database" << endl; + const char *mapping = SDL_GameControllerMapping(controller); + if (!mapping) { + WARN_LOG(Log::System, "Could not find mapping in SDL2 controller database"); } else { - cout << "SUCCESS, mapping is:" << endl << mapping << endl; + INFO_LOG(Log::System, "SUCCESS, mapping is: %s", mapping); } } else { SDL_GameControllerClose(controller); @@ -239,7 +236,7 @@ void SDLJoystick::ProcessInput(const SDL_Event &event){ int prevNumControllers = controllers.size(); setUpController(event.cdevice.which); if (prevNumControllers == 0 && controllers.size() > 0) { - cout << "pad 1 has been assigned to control pad: " << SDL_GameControllerName(controllers.front()) << endl; + INFO_LOG(Log::System, "pad 1 has been assigned to control pad: %s", SDL_GameControllerName(controllers.front())); } break; } @@ -248,8 +245,8 @@ void SDLJoystick::ProcessInput(const SDL_Event &event){ int SDLJoystick::getDeviceIndex(int instanceId) { auto it = controllerDeviceMap.find(instanceId); if (it == controllerDeviceMap.end()) { - // could not find device - return -1; + // could not find device + return -1; } return it->second; } diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index ee290a8467..f3bfd6cb45 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -36,6 +36,7 @@ SDLJoystick *joystick = NULL; #include "Common/Math/math_util.h" #include "Common/GPU/OpenGL/GLRenderManager.h" #include "Common/Profiler/Profiler.h" +#include "Common/Log/LogManager.h" #if defined(VK_USE_PLATFORM_XLIB_KHR) #include @@ -1150,6 +1151,8 @@ int main(int argc, char *argv[]) { TimeInit(); + g_logManager.EnableOutput(LogOutput::Stdio); + #ifdef HAVE_LIBNX socketInitializeDefault(); nxlinkStdio(); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 99dd0791d3..04257f98cc 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -644,18 +644,23 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch } } - if (fileToLog) + if (fileToLog) { + g_logManager.EnableOutput(LogOutput::File); g_logManager.ChangeFileLog(Path(fileToLog)); + } if (forceLogLevel) g_logManager.SetAllLogLevels(logLevel); PostLoadConfig(); -#if PPSSPP_PLATFORM(ANDROID) || (defined(MOBILE_DEVICE) && !defined(_DEBUG)) +#if PPSSPP_PLATFORM(ANDROID) + // Stdio is used for Android logging too. + g_logManager.EnableOutput(LogOutput::Stdio); +#elif (defined(MOBILE_DEVICE) && !defined(_DEBUG)) // Enable basic logging for any kind of mobile device, since LogManager doesn't. - // Printf is used for Android logging too. // The MOBILE_DEVICE/_DEBUG condition matches LogManager.cpp. + // TODO: Why not use stdio? g_logManager.EnableOutput(LogOutput::Printf); #endif diff --git a/ios/main.mm b/ios/main.mm index a2eb0f28ed..bef02d0a26 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -35,6 +35,7 @@ #include "Common/Thread/ThreadUtil.h" #include "Core/Config.h" #include "Common/Log.h" +#include "Common/Log/LogManager.h" #include "UI/DarwinFileSystemServices.h" // Compile out all the hackery in app store builds. @@ -578,6 +579,8 @@ int main(int argc, char *argv[]) g_iosVersionMajor = 14; } + g_logManager.EnableOutput(LogOutput::Stdio); + #if PPSSPP_PLATFORM(IOS_APP_STORE) g_jitAvailable = false; #else