Finally delete base/logging.cpp/h. Carefully preserve behaviour on Android.

There's more cleanup to do ...
This commit is contained in:
Henrik Rydgård committed 2020-08-15 19:09:09 +02:00
1 parent 3c412ea21e
commit f0d2f24658
10 files changed
+66 -161

No files matched your search

-2
View File
@@ -822,7 +822,6 @@ elseif(WIN32)
else()
link_directories(dx9sdk/Lib/x86)
endif()
set(nativeExtra ${nativeExtra} ext/native/base/logging.cpp)
elseif(TARGET SDL2::SDL2)
set(TargetBin PPSSPPSDL)
# Require SDL
@@ -934,7 +933,6 @@ add_library(native STATIC
ext/native/base/display.cpp
ext/native/base/display.h
ext/native/base/linked_ptr.h
ext/native/base/logging.h
ext/native/base/stringutil.cpp
ext/native/base/stringutil.h
ext/native/base/timeutil.cpp
+16 -19
View File
@@ -44,9 +44,6 @@
#endif
#include "base/display.h"
#include "base/logging.h" // For "AndroidLogger". TODO: Remove.
#include "base/stringutil.h"
#include "base/timeutil.h"
#include "base/NativeApp.h"
@@ -70,12 +67,16 @@
#include "ui/view.h"
#include "util/text/utf8.h"
#include "android/jni/app-android.h"
#include "Common/CPUDetect.h"
#include "Common/FileUtil.h"
#include "Common/KeyMap.h"
#include "Common/LogManager.h"
#include "Common/MemArena.h"
#include "Common/GraphicsContext.h"
#include "Common/OSVersion.h"
#include "Core/Config.h"
#include "Core/ConfigValues.h"
#include "Core/Core.h"
@@ -93,8 +94,8 @@
#include "Core/Util/GameManager.h"
#include "Core/Util/AudioFormat.h"
#include "Core/WebServer.h"
#include "GPU/GPUInterface.h"
#include "GPU/GPUInterface.h"
#include "UI/BackgroundAudio.h"
#include "UI/ControlMappingScreen.h"
#include "UI/DiscordIntegration.h"
@@ -108,10 +109,6 @@
#include "UI/TiltEventProcessor.h"
#include "UI/TextureUtil.h"
#if !defined(MOBILE_DEVICE)
#include "Common/KeyMap.h"
#endif
#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI)
#include "Qt/QtHost.h"
#endif
@@ -183,7 +180,7 @@ WindowsAudioBackend *winAudioBackend;
std::thread *graphicsLoadThread;
class AndroidLogger : public LogListener {
class PrintfLogger : public LogListener {
public:
void Log(const LogMessage &message) override {
// Log with simplified headers as Android already provides timestamp etc.
@@ -191,17 +188,17 @@ public:
case LogTypes::LVERBOSE:
case LogTypes::LDEBUG:
case LogTypes::LINFO:
ILOG("[%s] %s", message.log, message.msg.c_str());
printf("INFO [%s] %s", message.log, message.msg.c_str());
break;
case LogTypes::LERROR:
ELOG("[%s] %s", message.log, message.msg.c_str());
printf("ERR [%s] %s", message.log, message.msg.c_str());
break;
case LogTypes::LWARNING:
WLOG("[%s] %s", message.log, message.msg.c_str());
printf("WARN [%s] %s", message.log, message.msg.c_str());
break;
case LogTypes::LNOTICE:
default:
ILOG("[%s] !!! %s", message.log, message.msg.c_str());
printf("NOTE [%s] !!! %s", message.log, message.msg.c_str());
break;
}
}
@@ -214,7 +211,7 @@ int Win32Mix(short *buffer, int numSamples, int bits, int rate, int channels) {
#endif
// globals
static AndroidLogger *logger = nullptr;
static LogListener *logger = nullptr;
std::string boot_filename = "";
void NativeHost::InitSound() {
@@ -661,10 +658,13 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
PostLoadConfig();
#if defined(__ANDROID__) || (defined(MOBILE_DEVICE) && !defined(_DEBUG))
#if PPSSPP_PLATFORM(ANDROID)
logger = new AndroidLogger();
logman->AddListener(logger);
#elif (defined(MOBILE_DEVICE) && !defined(_DEBUG))
// Enable basic logging for any kind of mobile device, since LogManager doesn't.
// The MOBILE_DEVICE/_DEBUG condition matches LogManager.cpp.
logger = new AndroidLogger();
logger = new PrintfLogger();
logman->AddListener(logger);
#endif
@@ -1408,9 +1408,6 @@ void NativeShutdown() {
g_Discord.Shutdown();
delete logger;
logger = nullptr;
// Previously we did exit() here on Android but that makes it hard to do things like restart on backend change.
// I think we handle most globals correctly or correct-enough now.
}
-2
View File
@@ -385,7 +385,6 @@
<ClInclude Include="..\..\ext\native\base\colorutil.h" />
<ClInclude Include="..\..\ext\native\base\display.h" />
<ClInclude Include="..\..\ext\native\base\linked_ptr.h" />
<ClInclude Include="..\..\ext\native\base\logging.h" />
<ClInclude Include="..\..\ext\native\base\NativeApp.h" />
<ClInclude Include="..\..\ext\native\base\NKCodeFromQt.h" />
<ClInclude Include="..\..\ext\native\base\NKCodeFromSDL.h" />
@@ -479,7 +478,6 @@
<ClCompile Include="..\..\ext\native\base\buffer.cpp" />
<ClCompile Include="..\..\ext\native\base\colorutil.cpp" />
<ClCompile Include="..\..\ext\native\base\display.cpp" />
<ClCompile Include="..\..\ext\native\base\logging.cpp" />
<ClCompile Include="..\..\ext\native\base\stringutil.cpp" />
<ClCompile Include="..\..\ext\native\base\timeutil.cpp" />
<ClCompile Include="..\..\ext\native\data\base64.cpp" />
+2 -1
View File
@@ -610,8 +610,9 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
// - It should be possible to log to a file without showing the console.
LogManager::GetInstance()->GetConsoleListener()->Init(showLog, 150, 120, "PPSSPP Debug Console");
if (debugLogLevel)
if (debugLogLevel) {
LogManager::GetInstance()->SetAllLogLevels(LogTypes::LDEBUG);
}
timeBeginPeriod(1); // TODO: Evaluate if this makes sense to keep.
+40
View File
@@ -16,6 +16,8 @@
#ifndef _MSC_VER
#include <jni.h>
#include <android/native_window_jni.h>
#include <android/log.h>
#elif !defined(JNIEXPORT)
// Just for better highlighting in MSVC if opening this file.
// Not having types makes it get confused and say everything is wrong.
@@ -173,6 +175,44 @@ static std::map<SystemPermission, PermissionStatus> permissions;
AndroidGraphicsContext *graphicsContext;
#ifndef LOG_APP_NAME
#define LOG_APP_NAME "PPSSPP"
#endif
#ifdef _DEBUG
#define DLOG(...) __android_log_print(ANDROID_LOG_INFO, LOG_APP_NAME, __VA_ARGS__);
#else
#define DLOG(...)
#endif
#define ILOG(...) __android_log_print(ANDROID_LOG_INFO, LOG_APP_NAME, __VA_ARGS__);
#define WLOG(...) __android_log_print(ANDROID_LOG_WARN, LOG_APP_NAME, __VA_ARGS__);
#define ELOG(...) __android_log_print(ANDROID_LOG_ERROR, LOG_APP_NAME, __VA_ARGS__);
#define FLOG(...) __android_log_print(ANDROID_LOG_FATAL, LOG_APP_NAME, __VA_ARGS__);
#define MessageBox(a, b, c, d) __android_log_print(ANDROID_LOG_INFO, APP_NAME, "%s %s", (b), (c));
void AndroidLogger::Log(const LogMessage &message) {
// Log with simplified headers as Android already provides timestamp etc.
switch (message.level) {
case LogTypes::LVERBOSE:
case LogTypes::LDEBUG:
case LogTypes::LINFO:
ILOG("[%s] %s", message.log, message.msg.c_str());
break;
case LogTypes::LERROR:
ELOG("[%s] %s", message.log, message.msg.c_str());
break;
case LogTypes::LWARNING:
WLOG("[%s] %s", message.log, message.msg.c_str());
break;
case LogTypes::LNOTICE:
default:
ILOG("[%s] !!! %s", message.log, message.msg.c_str());
break;
}
}
JNIEnv* getEnv() {
JNIEnv *env;
int status = gJvm->GetEnv((void**)&env, JNI_VERSION_1_6);
+7
View File
@@ -2,6 +2,8 @@
#include "ppsspp_config.h"
#include "Common/LogManager.h"
#if PPSSPP_PLATFORM(ANDROID)
#include <jni.h>
@@ -10,3 +12,8 @@ jclass findClass(const char* name);
JNIEnv* getEnv();
#endif
class AndroidLogger : public LogListener {
public:
void Log(const LogMessage &message) override;
};
-9
View File
@@ -1,9 +0,0 @@
#include <cstring>
const char *GetFn(const char *fn) {
const char *p = strrchr(fn, '\\');
if (p)
return p + 1;
else
return fn;
}
-124
View File
@@ -1,124 +0,0 @@
#pragma once
#include <cstring>
#include "ppsspp_config.h"
#include "base/backtrace.h"
// Simple wrapper around Android's logging interface that also allows other
// implementations, and also some misc utilities.
#ifdef _MSC_VER
// Disable annoying warnings in VS
#pragma warning (disable:4996) //strcpy may be dangerous, etc.
#endif
#undef Crash
#include <stdio.h>
// Logging
#ifdef _WIN32
#ifdef _M_X64
inline void Crash() { int *x = (int *)1337; *x = 1; }
#elif defined(_M_IX86)
inline void Crash() { __asm { int 3 }; }
#elif defined(_M_ARM)
inline void Crash() { int *x = (int *)1337; *x = 1; }
#elif defined(_M_ARM64)
inline void Crash() { int* x = (int*)1337; *x = 1; }
#endif
#else
#if defined(_M_IX86) || defined(_M_X64)
inline void Crash() {
PrintBacktraceToStderr();
asm("int $0x3");
}
#else
inline void Crash() {
PrintBacktraceToStderr();
char *p = (char *)1337;
*p = 1;
}
#endif
#endif
#if defined(__ANDROID__)
#include <android/log.h>
// Must only be used for logging
#ifndef APP_NAME
#define APP_NAME "PPSSPP"
#endif
#ifdef _DEBUG
#define DLOG(...) __android_log_print(ANDROID_LOG_INFO, APP_NAME, __VA_ARGS__);
#else
#define DLOG(...)
#endif
#define ILOG(...) __android_log_print(ANDROID_LOG_INFO, APP_NAME, __VA_ARGS__);
#define WLOG(...) __android_log_print(ANDROID_LOG_WARN, APP_NAME, __VA_ARGS__);
#define ELOG(...) __android_log_print(ANDROID_LOG_ERROR, APP_NAME, __VA_ARGS__);
#define FLOG(...) __android_log_print(ANDROID_LOG_FATAL, APP_NAME, __VA_ARGS__);
#define MessageBox(a, b, c, d) __android_log_print(ANDROID_LOG_INFO, APP_NAME, "%s %s", (b), (c));
#else
#ifdef _WIN32
const char *GetFn(const char *fn);
#define XLOG_IMPL(type, ...) do {\
char temp[512]; \
char *p = temp; \
int len = snprintf(p, sizeof(temp), type ": %s:%i: ", GetFn(__FILE__), __LINE__); \
if (len < sizeof(temp)) { \
p += len; \
p += snprintf(p, sizeof(temp) - len - 3, type ": " __VA_ARGS__); \
if (p > temp + sizeof(temp) - 3) \
p = temp + sizeof(temp) - 3; \
p += sprintf(p, "\n"); \
OutputDebugStringUTF8(temp); \
} \
} while (false)
#define DUMPLOG(x) OutputDebugStringUTF8(x)
#ifdef _DEBUG
#define DLOG(...) XLOG_IMPL("D", __VA_ARGS__)
#else
#define DLOG(...)
#endif
#define ILOG(...) XLOG_IMPL("I", __VA_ARGS__)
#define WLOG(...) XLOG_IMPL("W", __VA_ARGS__)
#define ELOG(...) XLOG_IMPL("E", __VA_ARGS__)
#define FLOG(...) do {XLOG_IMPL("F", __VA_ARGS__); Crash();} while (false)
#else
#include <stdio.h>
inline const char *removePath(const char *str) {
const char *slash = strrchr(str, '/');
return slash ? (slash + 1) : str;
}
#ifdef _DEBUG
#define DLOG(...) {printf("D: %s:%i: ", removePath(__FILE__), __LINE__); printf("D: " __VA_ARGS__); printf("\n");}
#else
#define DLOG(...)
#endif
#define ILOG(...) {printf("I: %s:%i: ", removePath(__FILE__), __LINE__); printf(__VA_ARGS__); printf("\n");}
#define WLOG(...) {printf("W: %s:%i: ", removePath(__FILE__), __LINE__); printf(__VA_ARGS__); printf("\n");}
#define ELOG(...) {printf("E: %s:%i: ", removePath(__FILE__), __LINE__); printf(__VA_ARGS__); printf("\n");}
#define FLOG(...) {printf("F: %s:%i: ", removePath(__FILE__), __LINE__); printf(__VA_ARGS__); printf("\n"); Crash();}
#endif
#endif
+1 -3
View File
@@ -387,7 +387,6 @@
<ClInclude Include="base\buffer.h" />
<ClInclude Include="base\colorutil.h" />
<ClInclude Include="base\display.h" />
<ClInclude Include="base\logging.h" />
<ClInclude Include="base\NativeApp.h" />
<ClInclude Include="base\stringutil.h" />
<ClInclude Include="base\timeutil.h" />
@@ -496,7 +495,6 @@
<ClCompile Include="base\buffer.cpp" />
<ClCompile Include="base\colorutil.cpp" />
<ClCompile Include="base\display.cpp" />
<ClCompile Include="base\logging.cpp" />
<ClCompile Include="..\..\SDL\SDLMain.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -1217,4 +1215,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
-1
View File
@@ -215,7 +215,6 @@ SOURCES_CXX += \
$(EXTDIR)/native/base/buffer.cpp \
$(EXTDIR)/native/base/colorutil.cpp \
$(EXTDIR)/native/base/display.cpp \
$(EXTDIR)/native/base/logging.cpp \
$(EXTDIR)/native/base/stringutil.cpp \
$(EXTDIR)/native/base/timeutil.cpp \
$(EXTDIR)/native/data/compression.cpp \