Logging: Add customizable logging backends and fmtlib based macros
* Change the logging backend to support multiple sinks through the Backend Interface * Add a new set of logging macros to use fmtlib instead. * Qt: Compile as GUI application on windows to make the console hidden by default. Add filter configuration and a button to open log location. * SDL: Migrate to the new logging macros
This commit is contained in:
parent
3cda637cb1
commit
0daac3020e
25 changed files with 527 additions and 140 deletions
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "citra/config.h"
|
||||
#include "citra/emu_window/emu_window_sdl2.h"
|
||||
#include "common/common_paths.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/logging/backend.h"
|
||||
#include "common/logging/filter.h"
|
||||
|
@ -60,39 +61,39 @@ static void PrintVersion() {
|
|||
static void OnStateChanged(const Network::RoomMember::State& state) {
|
||||
switch (state) {
|
||||
case Network::RoomMember::State::Idle:
|
||||
LOG_DEBUG(Network, "Network is idle");
|
||||
NGLOG_DEBUG(Network, "Network is idle");
|
||||
break;
|
||||
case Network::RoomMember::State::Joining:
|
||||
LOG_DEBUG(Network, "Connection sequence to room started");
|
||||
NGLOG_DEBUG(Network, "Connection sequence to room started");
|
||||
break;
|
||||
case Network::RoomMember::State::Joined:
|
||||
LOG_DEBUG(Network, "Successfully joined to the room");
|
||||
NGLOG_DEBUG(Network, "Successfully joined to the room");
|
||||
break;
|
||||
case Network::RoomMember::State::LostConnection:
|
||||
LOG_DEBUG(Network, "Lost connection to the room");
|
||||
NGLOG_DEBUG(Network, "Lost connection to the room");
|
||||
break;
|
||||
case Network::RoomMember::State::CouldNotConnect:
|
||||
LOG_ERROR(Network, "State: CouldNotConnect");
|
||||
NGLOG_ERROR(Network, "State: CouldNotConnect");
|
||||
exit(1);
|
||||
break;
|
||||
case Network::RoomMember::State::NameCollision:
|
||||
LOG_ERROR(
|
||||
NGLOG_ERROR(
|
||||
Network,
|
||||
"You tried to use the same nickname then another user that is connected to the Room");
|
||||
exit(1);
|
||||
break;
|
||||
case Network::RoomMember::State::MacCollision:
|
||||
LOG_ERROR(Network, "You tried to use the same MAC-Address then another user that is "
|
||||
"connected to the Room");
|
||||
NGLOG_ERROR(Network, "You tried to use the same MAC-Address then another user that is "
|
||||
"connected to the Room");
|
||||
exit(1);
|
||||
break;
|
||||
case Network::RoomMember::State::WrongPassword:
|
||||
LOG_ERROR(Network, "Room replied with: Wrong password");
|
||||
NGLOG_ERROR(Network, "Room replied with: Wrong password");
|
||||
exit(1);
|
||||
break;
|
||||
case Network::RoomMember::State::WrongVersion:
|
||||
LOG_ERROR(Network,
|
||||
"You are using a different version then the room you are trying to connect to");
|
||||
NGLOG_ERROR(Network,
|
||||
"You are using a different version then the room you are trying to connect to");
|
||||
exit(1);
|
||||
break;
|
||||
default:
|
||||
|
@ -119,7 +120,7 @@ int main(int argc, char** argv) {
|
|||
auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w);
|
||||
|
||||
if (argv_w == nullptr) {
|
||||
LOG_CRITICAL(Frontend, "Failed to get command line arguments");
|
||||
NGLOG_CRITICAL(Frontend, "Failed to get command line arguments");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
@ -155,7 +156,7 @@ int main(int argc, char** argv) {
|
|||
break;
|
||||
case 'i': {
|
||||
const auto cia_progress = [](size_t written, size_t total) {
|
||||
LOG_INFO(Frontend, "%02zu%%", (written * 100 / total));
|
||||
NGLOG_INFO(Frontend, "{:02d}%", (written * 100 / total));
|
||||
};
|
||||
if (Service::AM::InstallCIA(std::string(optarg), cia_progress) !=
|
||||
Service::AM::InstallStatus::Success)
|
||||
|
@ -223,23 +224,27 @@ int main(int argc, char** argv) {
|
|||
LocalFree(argv_w);
|
||||
#endif
|
||||
|
||||
Log::Filter log_filter(Log::Level::Debug);
|
||||
Log::SetFilter(&log_filter);
|
||||
|
||||
MicroProfileOnThreadCreate("EmuThread");
|
||||
SCOPE_EXIT({ MicroProfileShutdown(); });
|
||||
|
||||
if (filepath.empty()) {
|
||||
LOG_CRITICAL(Frontend, "Failed to load ROM: No ROM specified");
|
||||
NGLOG_CRITICAL(Frontend, "Failed to load ROM: No ROM specified");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!movie_record.empty() && !movie_play.empty()) {
|
||||
LOG_CRITICAL(Frontend, "Cannot both play and record a movie");
|
||||
NGLOG_CRITICAL(Frontend, "Cannot both play and record a movie");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Log::Filter log_filter;
|
||||
log_filter.ParseFilterString(Settings::values.log_filter);
|
||||
Log::SetGlobalFilter(log_filter);
|
||||
|
||||
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
|
||||
FileUtil::CreateFullPath(FileUtil::GetUserPath(D_LOGS_IDX));
|
||||
Log::AddBackend(
|
||||
std::make_unique<Log::FileBackend>(FileUtil::GetUserPath(D_LOGS_IDX) + LOG_FILE));
|
||||
|
||||
// Apply the command line arguments
|
||||
Settings::values.gdbstub_port = gdb_port;
|
||||
|
@ -258,28 +263,28 @@ int main(int argc, char** argv) {
|
|||
|
||||
switch (load_result) {
|
||||
case Core::System::ResultStatus::ErrorGetLoader:
|
||||
LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filepath.c_str());
|
||||
NGLOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filepath);
|
||||
return -1;
|
||||
case Core::System::ResultStatus::ErrorLoader:
|
||||
LOG_CRITICAL(Frontend, "Failed to load ROM!");
|
||||
NGLOG_CRITICAL(Frontend, "Failed to load ROM!");
|
||||
return -1;
|
||||
case Core::System::ResultStatus::ErrorLoader_ErrorEncrypted:
|
||||
LOG_CRITICAL(Frontend, "The game that you are trying to load must be decrypted before "
|
||||
"being used with Citra. \n\n For more information on dumping and "
|
||||
"decrypting games, please refer to: "
|
||||
"https://citra-emu.org/wiki/dumping-game-cartridges/");
|
||||
NGLOG_CRITICAL(Frontend, "The game that you are trying to load must be decrypted before "
|
||||
"being used with Citra. \n\n For more information on dumping and "
|
||||
"decrypting games, please refer to: "
|
||||
"https://citra-emu.org/wiki/dumping-game-cartridges/");
|
||||
return -1;
|
||||
case Core::System::ResultStatus::ErrorLoader_ErrorInvalidFormat:
|
||||
LOG_CRITICAL(Frontend, "Error while loading ROM: The ROM format is not supported.");
|
||||
NGLOG_CRITICAL(Frontend, "Error while loading ROM: The ROM format is not supported.");
|
||||
return -1;
|
||||
case Core::System::ResultStatus::ErrorNotInitialized:
|
||||
LOG_CRITICAL(Frontend, "CPUCore not initialized");
|
||||
NGLOG_CRITICAL(Frontend, "CPUCore not initialized");
|
||||
return -1;
|
||||
case Core::System::ResultStatus::ErrorSystemMode:
|
||||
LOG_CRITICAL(Frontend, "Failed to determine system mode!");
|
||||
NGLOG_CRITICAL(Frontend, "Failed to determine system mode!");
|
||||
return -1;
|
||||
case Core::System::ResultStatus::ErrorVideoCore:
|
||||
LOG_CRITICAL(Frontend, "VideoCore not initialized");
|
||||
NGLOG_CRITICAL(Frontend, "VideoCore not initialized");
|
||||
return -1;
|
||||
case Core::System::ResultStatus::Success:
|
||||
break; // Expected case
|
||||
|
@ -291,11 +296,11 @@ int main(int argc, char** argv) {
|
|||
if (auto member = Network::GetRoomMember().lock()) {
|
||||
member->BindOnChatMessageRecieved(OnMessageReceived);
|
||||
member->BindOnStateChanged(OnStateChanged);
|
||||
LOG_DEBUG(Network, "Start connection to %s:%u with nickname %s", address.c_str(), port,
|
||||
nickname.c_str());
|
||||
NGLOG_DEBUG(Network, "Start connection to {}:{} with nickname {}", address, port,
|
||||
nickname);
|
||||
member->Join(nickname, address.c_str(), port, 0, Network::NoPreferredMac, password);
|
||||
} else {
|
||||
LOG_ERROR(Network, "Could not access RoomMember");
|
||||
NGLOG_ERROR(Network, "Could not access RoomMember");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,17 +27,17 @@ bool Config::LoadINI(const std::string& default_contents, bool retry) {
|
|||
const char* location = this->sdl2_config_loc.c_str();
|
||||
if (sdl2_config->ParseError() < 0) {
|
||||
if (retry) {
|
||||
LOG_WARNING(Config, "Failed to load %s. Creating file from defaults...", location);
|
||||
NGLOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location);
|
||||
FileUtil::CreateFullPath(location);
|
||||
FileUtil::WriteStringToFile(true, default_contents, location);
|
||||
sdl2_config = std::make_unique<INIReader>(location); // Reopen file
|
||||
|
||||
return LoadINI(default_contents, false);
|
||||
}
|
||||
LOG_ERROR(Config, "Failed.");
|
||||
NGLOG_ERROR(Config, "Failed.");
|
||||
return false;
|
||||
}
|
||||
LOG_INFO(Config, "Successfully loaded %s", location);
|
||||
NGLOG_INFO(Config, "Successfully loaded {}", location);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -49,10 +49,18 @@ static const std::array<int, Settings::NativeButton::NumButtons> default_buttons
|
|||
|
||||
static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs{{
|
||||
{
|
||||
SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_D,
|
||||
SDL_SCANCODE_UP,
|
||||
SDL_SCANCODE_DOWN,
|
||||
SDL_SCANCODE_LEFT,
|
||||
SDL_SCANCODE_RIGHT,
|
||||
SDL_SCANCODE_D,
|
||||
},
|
||||
{
|
||||
SDL_SCANCODE_I, SDL_SCANCODE_K, SDL_SCANCODE_J, SDL_SCANCODE_L, SDL_SCANCODE_D,
|
||||
SDL_SCANCODE_I,
|
||||
SDL_SCANCODE_K,
|
||||
SDL_SCANCODE_J,
|
||||
SDL_SCANCODE_L,
|
||||
SDL_SCANCODE_D,
|
||||
},
|
||||
}};
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ EmuWindow_SDL2::EmuWindow_SDL2() {
|
|||
|
||||
// Initialize the window
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
LOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting...");
|
||||
NGLOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting...");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -89,19 +89,19 @@ EmuWindow_SDL2::EmuWindow_SDL2() {
|
|||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
|
||||
if (render_window == nullptr) {
|
||||
LOG_CRITICAL(Frontend, "Failed to create SDL2 window: %s", SDL_GetError());
|
||||
NGLOG_CRITICAL(Frontend, "Failed to create SDL2 window: {}", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gl_context = SDL_GL_CreateContext(render_window);
|
||||
|
||||
if (gl_context == nullptr) {
|
||||
LOG_CRITICAL(Frontend, "Failed to create SDL2 GL context: %s", SDL_GetError());
|
||||
NGLOG_CRITICAL(Frontend, "Failed to create SDL2 GL context: {}", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!gladLoadGLLoader(static_cast<GLADloadproc>(SDL_GL_GetProcAddress))) {
|
||||
LOG_CRITICAL(Frontend, "Failed to initialize GL functions: %s", SDL_GetError());
|
||||
NGLOG_CRITICAL(Frontend, "Failed to initialize GL functions: {}", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue