Commit a95f45b1 authored by James's avatar James
Browse files

Hook up LibRetro's logging interface to Citra's

parent 21423bb3
......@@ -13,7 +13,8 @@ add_library(citra_libretro SHARED
environment.h
core_settings.cpp
core_settings.h
)
libretro_logger.cpp
libretro_logger.h)
create_target_directory_groups(citra_libretro)
......
......@@ -16,6 +16,7 @@
#include "citra_libretro/citra_libretro.h"
#include "citra_libretro/core_settings.h"
#include "citra_libretro/environment.h"
#include "citra_libretro/libretro_logger.h"
#include "citra_libretro/input/input_factory.h"
#include "common/logging/backend.h"
#include "common/logging/filter.h"
......@@ -40,6 +41,15 @@ CitraLibRetro* emu_instance;
void retro_init() {
emu_instance = new CitraLibRetro();
Log::SetGlobalFilter(emu_instance->log_filter);
// Check to see if the frontend is providing us with logging functionality
auto callback = LibRetro::GetLoggingBackend();
if (callback != nullptr) {
Log::AddBackend(std::make_unique<LibRetroLogger>(callback));
} else {
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
}
LOG_DEBUG(Frontend, "Initialising core...");
LibRetro::Input::Init();
......
......@@ -108,6 +108,15 @@ std::string GetSystemDir() {
return std::string(var);
}
retro_log_printf_t GetLoggingBackend() {
retro_log_callback callback{};
if (!environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &callback)) {
LOG_WARNING(Frontend, "No logging backend provided by LibRetro.");
return nullptr;
}
return callback.log;
}
int16_t CheckInput(unsigned port, unsigned device, unsigned index, unsigned id) {
return input_state_cb(port, device, index, id);
}
......
......@@ -36,6 +36,9 @@ std::string GetSystemDir();
/// Fetches a variable by key name.
std::string FetchVariable(std::string key, std::string def);
/// Returns a logging backend, or null if the frontend refuses to provide one.
retro_log_printf_t GetLoggingBackend();
/// Displays information about the kinds of controllers that this Citra recreates.
bool SetControllerInfo(const retro_controller_info info[]);
......
// Copyright 2018 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/logging/text_formatter.h"
#include "common/assert.h"
#include "libretro_logger.h"
LibRetroLogger::LibRetroLogger(retro_log_printf_t callback) : callback(callback) {}
const char *LibRetroLogger::GetName() const {
return "LibRetro";
}
void LibRetroLogger::Write(const Log::Entry &entry) {
retro_log_level log_level;
switch (entry.log_level) {
case Log::Level::Trace:
log_level = retro_log_level::RETRO_LOG_DEBUG;
break;
case Log::Level::Debug:
log_level = retro_log_level::RETRO_LOG_DEBUG;
break;
case Log::Level::Info:
log_level = retro_log_level::RETRO_LOG_INFO;
break;
case Log::Level::Warning:
log_level = retro_log_level::RETRO_LOG_WARN;
break;
case Log::Level::Error:
log_level = retro_log_level::RETRO_LOG_ERROR;
break;
case Log::Level::Critical:
log_level = retro_log_level::RETRO_LOG_ERROR;
break;
default:
UNREACHABLE();
}
const char* class_name = GetLogClassName(entry.log_class);
auto str = fmt::format("{} @ {}:{}:{}: {}\n", class_name, entry.filename, entry.function, entry.line_num,
entry.message);
callback(log_level, str.c_str());
}
// Copyright 2018 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include "common/logging/backend.h"
#include "libretro.h"
class LibRetroLogger : public Log::Backend {
public:
explicit LibRetroLogger(retro_log_printf_t callback);
const char *GetName() const override;
void Write(const Log::Entry &entry) override;
private:
retro_log_printf_t callback;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment