Use android-only logging on config to prevent crash due to logging not being initialized

This commit is contained in:
amwatson 2024-05-13 22:07:29 -05:00
parent b5b2d6889c
commit 3421fcf661
2 changed files with 11 additions and 5 deletions

View file

@ -22,6 +22,7 @@
#include "jni/default_ini.h"
#include "jni/input_manager.h"
#include "network/network_settings.h"
#include "vr/utils/LogUtils.h"
#include "vr/vr_settings.h"
#include "vr/utils/LogUtils.h"
@ -43,7 +44,7 @@ bool Config::LoadINI(const std::string& default_contents, bool retry) {
const std::string& location = this->sdl2_config_loc;
if (sdl2_config == nullptr || sdl2_config->ParseError() < 0) {
if (retry) {
LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location);
ANDROID_ONLY_LOGW("Failed to load %s. Creating file from defaults...", location.c_str());
FileUtil::CreateFullPath(location);
FileUtil::WriteStringToFile(true, location, default_contents);
std::string ini_buffer;
@ -53,10 +54,10 @@ bool Config::LoadINI(const std::string& default_contents, bool retry) {
return LoadINI(default_contents, false);
}
LOG_ERROR(Config, "Failed.");
ANDROID_ONLY_LOGE("Failed.");
return false;
}
LOG_INFO(Config, "Successfully loaded {}", location);
ANDROID_ONLY_LOGI("Successfully loaded %s", location.c_str());
return true;
}
@ -274,7 +275,7 @@ void Config::ReadValues() {
// be used to determine per-hmd settings in the config
{
const std::string hmdTypeStr = VRSettings::GetHMDTypeStr();
LOG_INFO(Config, "HMD type: {}", hmdTypeStr.c_str());
ANDROID_ONLY_LOGI("HMD type: %s", hmdTypeStr.c_str());
VRSettings::values.hmd_type = VRSettings::HmdTypeFromStr(hmdTypeStr);
}
VRSettings::values.vr_environment = VRSettings::values.extra_performance_mode_enabled ?
@ -307,7 +308,7 @@ void Config::ReadValues() {
Settings::values.vr_immersive_eye_indicator = VRSettings::values.vr_immersive_eye_indicator;
if (Settings::values.vr_immersive_mode.GetValue() > 0) {
LOG_INFO(Config, "VR immersive mode enabled");
ANDROID_ONLY_LOGI("VR immersive mode enabled");
// no point rendering passthrough in immersive mode
VRSettings::values.vr_environment =

View file

@ -27,6 +27,11 @@ License : Licensed under GPLv3 or any later version.
#define ALOGV(...) LOG_TRACE(VR, __VA_ARGS__)
#define ALOGD(...) LOG_DEBUG(VR, __VA_ARGS__)
// Use these for logging before logging system is initialized
#define ANDROID_ONLY_LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define ANDROID_ONLY_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define ANDROID_ONLY_LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define FAIL(...) \
do { \
__android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__); \