logging: Address some issues

This commit is contained in:
GPUCode 2023-06-24 18:30:13 +03:00
parent 9c3e2d0f50
commit ba98bf058a
11 changed files with 19 additions and 34 deletions

View File

@ -180,12 +180,6 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION) != JNI_OK) if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION) != JNI_OK)
return JNI_ERR; return JNI_ERR;
// Initialize Logger
Log::Filter log_filter;
log_filter.ParseFilterString(Settings::values.log_filter.GetValue());
Log::SetGlobalFilter(log_filter);
Log::AddBackend(std::make_unique<Log::LogcatBackend>());
// Initialize misc classes // Initialize misc classes
s_savestate_info_class = reinterpret_cast<jclass>( s_savestate_info_class = reinterpret_cast<jclass>(
env->NewGlobalRef(env->FindClass("org/citra/citra_emu/NativeLibrary$SavestateInfo"))); env->NewGlobalRef(env->FindClass("org/citra/citra_emu/NativeLibrary$SavestateInfo")));

View File

@ -438,10 +438,8 @@ void Java_org_citra_citra_1emu_NativeLibrary_CreateConfigFile(JNIEnv* env,
void Java_org_citra_citra_1emu_NativeLibrary_CreateLogFile(JNIEnv* env, void Java_org_citra_citra_1emu_NativeLibrary_CreateLogFile(JNIEnv* env,
[[maybe_unused]] jclass clazz) { [[maybe_unused]] jclass clazz) {
Log::RemoveBackend(Log::FileBackend::Name()); Common::Log::Initialize();
FileUtil::CreateFullPath(FileUtil::GetUserPath(FileUtil::UserPath::LogDir)); Common::Log::Start();
Log::AddBackend(std::make_unique<Log::FileBackend>(
FileUtil::GetUserPath(FileUtil::UserPath::LogDir) + LOG_FILE));
LOG_INFO(Frontend, "Logging backend initialised"); LOG_INFO(Frontend, "Logging backend initialised");
} }

View File

@ -330,7 +330,6 @@ int main(int argc, char** argv) {
return -1; return -1;
} }
Core::System::InitializeGlobalInstance();
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& movie = Core::Movie::GetInstance(); auto& movie = Core::Movie::GetInstance();

View File

@ -2880,7 +2880,6 @@ int main(int argc, char* argv[]) {
// generating shaders // generating shaders
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
Core::System::InitializeGlobalInstance();
auto& system{Core::System::GetInstance()}; auto& system{Core::System::GetInstance()};
GMainWindow main_window(system); GMainWindow main_window(system);

View File

@ -7,6 +7,7 @@
#include <atomic> #include <atomic>
#include <condition_variable> #include <condition_variable>
#include <cstddef> #include <cstddef>
#include <memory>
#include <mutex> #include <mutex>
#include <new> #include <new>
@ -94,7 +95,7 @@ private:
const size_t pos = write_index % Capacity; const size_t pos = write_index % Capacity;
// Emplace into the queue. // Emplace into the queue.
std::construct_at(std::addressof(m_data[pos]), std::forward<Args>(args)...); new (std::addressof(m_data[pos])) T(std::forward<Args>(args)...);
// Increment the write index. // Increment the write index.
++m_write_index; ++m_write_index;

View File

@ -8,9 +8,9 @@
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <unordered_map> #include <unordered_map>
#include <fmt/format.h>
#include <boost/iostreams/device/file_descriptor.hpp> #include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp> #include <boost/iostreams/stream.hpp>
#include <fmt/format.h>
#include "common/assert.h" #include "common/assert.h"
#include "common/common_funcs.h" #include "common/common_funcs.h"
#include "common/common_paths.h" #include "common/common_paths.h"

View File

@ -352,6 +352,9 @@ private:
lambda(static_cast<Backend&>(debugger_backend)); lambda(static_cast<Backend&>(debugger_backend));
lambda(static_cast<Backend&>(color_console_backend)); lambda(static_cast<Backend&>(color_console_backend));
lambda(static_cast<Backend&>(file_backend)); lambda(static_cast<Backend&>(file_backend));
#ifdef ANDROID
lambda(static_cast<Backend&>(lc_backend));
#endif
} }
static void Deleter(Impl* ptr) { static void Deleter(Impl* ptr) {
@ -394,6 +397,9 @@ private:
DebuggerBackend debugger_backend{}; DebuggerBackend debugger_backend{};
ColorConsoleBackend color_console_backend{}; ColorConsoleBackend color_console_backend{};
FileBackend file_backend; FileBackend file_backend;
#ifdef ANDROID
LogcatBackend lc_backend{};
#endif
MPSCQueue<Entry> message_queue{}; MPSCQueue<Entry> message_queue{};
std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};

View File

@ -5,7 +5,7 @@
#pragma once #pragma once
#include <type_traits> #include <type_traits>
#include <fmt/core.h> #include <fmt/format.h>
// adapted from https://github.com/fmtlib/fmt/issues/2704 // adapted from https://github.com/fmtlib/fmt/issues/2704
// a generic formatter for enum classes // a generic formatter for enum classes

View File

@ -52,6 +52,8 @@
namespace Core { namespace Core {
/*static*/ System System::s_instance;
template <> template <>
Core::System& Global() { Core::System& Global() {
return System::GetInstance(); return System::GetInstance();
@ -69,20 +71,6 @@ Core::Timing& Global() {
System::~System() = default; System::~System() = default;
System& System::GetInstance() {
if (!s_instance) {
throw std::runtime_error("Using System instance before its initialization");
}
return *s_instance;
}
void System::InitializeGlobalInstance() {
if (s_instance) {
throw std::runtime_error("Reinitializing Global System instance.");
}
s_instance = std::unique_ptr<System>(new System);
}
System::ResultStatus System::RunLoop(bool tight_loop) { System::ResultStatus System::RunLoop(bool tight_loop) {
status = ResultStatus::Success; status = ResultStatus::Success;
if (!IsPoweredOn()) { if (!IsPoweredOn()) {

View File

@ -73,9 +73,9 @@ public:
* Gets the instance of the System singleton class. * Gets the instance of the System singleton class.
* @returns Reference to the instance of the System singleton class. * @returns Reference to the instance of the System singleton class.
*/ */
[[nodiscard]] static System& GetInstance(); [[nodiscard]] static System& GetInstance() {
return s_instance;
static void InitializeGlobalInstance(); }
/// Enumeration representing the return values of the System Initialize and Load process. /// Enumeration representing the return values of the System Initialize and Load process.
enum class ResultStatus : u32 { enum class ResultStatus : u32 {
@ -392,7 +392,7 @@ private:
std::unique_ptr<Core::ExclusiveMonitor> exclusive_monitor; std::unique_ptr<Core::ExclusiveMonitor> exclusive_monitor;
private: private:
inline static std::unique_ptr<System> s_instance; static System s_instance;
std::atomic_bool is_powered_on{}; std::atomic_bool is_powered_on{};

View File

@ -8,7 +8,7 @@ add_executable(citra-room
create_target_directory_groups(citra-room) create_target_directory_groups(citra-room)
target_link_libraries(citra-room PRIVATE citra_common network) target_link_libraries(citra-room PRIVATE citra_common citra_core network)
if (ENABLE_WEB_SERVICE) if (ENABLE_WEB_SERVICE)
target_compile_definitions(citra-room PRIVATE -DENABLE_WEB_SERVICE) target_compile_definitions(citra-room PRIVATE -DENABLE_WEB_SERVICE)
target_link_libraries(citra-room PRIVATE web_service) target_link_libraries(citra-room PRIVATE web_service)