2014-10-28 08:36:00 +01:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
2014-12-17 06:38:14 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
2014-10-28 08:36:00 +01:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-07-14 18:20:00 +02:00
|
|
|
#include <array>
|
2018-02-20 01:51:27 +01:00
|
|
|
#include <fmt/format.h>
|
2014-10-28 08:36:00 +01:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Log {
|
|
|
|
|
2019-12-24 21:19:18 +01:00
|
|
|
// trims up to and including the last of ../, ..\, src/, src\ in a string
|
2020-03-07 05:41:00 +01:00
|
|
|
inline const char* TrimSourcePath(std::string_view source) {
|
2019-12-24 21:19:18 +01:00
|
|
|
const auto rfind = [source](const std::string_view match) {
|
|
|
|
return source.rfind(match) == source.npos ? 0 : (source.rfind(match) + match.size());
|
|
|
|
};
|
|
|
|
auto idx = std::max({rfind("src/"), rfind("src\\"), rfind("../"), rfind("..\\")});
|
|
|
|
return source.data() + idx;
|
|
|
|
}
|
|
|
|
|
2014-10-28 08:36:00 +01:00
|
|
|
/// Specifies the severity or level of detail of the log message.
|
|
|
|
enum class Level : u8 {
|
|
|
|
Trace, ///< Extremely detailed and repetitive debugging information that is likely to
|
2018-09-04 16:49:06 +02:00
|
|
|
///< pollute logs.
|
2014-10-28 08:36:00 +01:00
|
|
|
Debug, ///< Less detailed debugging information.
|
|
|
|
Info, ///< Status information from important points during execution.
|
|
|
|
Warning, ///< Minor or potential problems found during execution of a task.
|
|
|
|
Error, ///< Major problems found during execution of a task that prevent it from being
|
2018-09-04 16:49:06 +02:00
|
|
|
///< completed.
|
|
|
|
Critical, ///< Major problems during execution that threaten the stability of the entire
|
|
|
|
///< application.
|
2014-10-28 08:36:00 +01:00
|
|
|
|
|
|
|
Count ///< Total number of logging levels
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef u8 ClassType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies the sub-system that generated the log message.
|
|
|
|
*
|
2016-09-18 02:38:01 +02:00
|
|
|
* @note If you add a new entry here, also add a corresponding one to `ALL_LOG_CLASSES` in
|
|
|
|
* backend.cpp.
|
2014-10-28 08:36:00 +01:00
|
|
|
*/
|
|
|
|
enum class Class : ClassType {
|
2016-09-18 02:38:01 +02:00
|
|
|
Log, ///< Messages about the log system itself
|
|
|
|
Common, ///< Library routines
|
|
|
|
Common_Filesystem, ///< Filesystem interface library
|
|
|
|
Common_Memory, ///< Memory mapping and management functions
|
|
|
|
Core, ///< LLE emulation core
|
|
|
|
Core_ARM11, ///< ARM11 CPU core
|
|
|
|
Core_Timing, ///< CoreTiming functions
|
2018-11-17 02:01:10 +01:00
|
|
|
Core_Cheats, ///< Cheat functions
|
2016-09-18 02:38:01 +02:00
|
|
|
Config, ///< Emulator configuration (including commandline)
|
|
|
|
Debug, ///< Debugging tools
|
|
|
|
Debug_Emulated, ///< Debug messages from the emulated programs
|
|
|
|
Debug_GPU, ///< GPU debugging tools
|
|
|
|
Debug_Breakpoint, ///< Logging breakpoints and watchpoints
|
|
|
|
Debug_GDBStub, ///< GDB Stub
|
|
|
|
Kernel, ///< The HLE implementation of the CTR kernel
|
|
|
|
Kernel_SVC, ///< Kernel system calls
|
2018-06-20 06:01:54 +02:00
|
|
|
Applet, ///< HLE implementation of system applets. Each applet
|
2018-09-04 16:49:06 +02:00
|
|
|
///< should have its own subclass.
|
2018-06-20 06:01:54 +02:00
|
|
|
Applet_SWKBD, ///< The Software Keyboard applet
|
2016-09-18 02:38:01 +02:00
|
|
|
Service, ///< HLE implementation of system services. Each major service
|
2018-09-04 16:49:06 +02:00
|
|
|
///< should have its own subclass.
|
2016-09-18 02:38:01 +02:00
|
|
|
Service_SRV, ///< The SRV (Service Directory) implementation
|
|
|
|
Service_FRD, ///< The FRD (Friends) service
|
|
|
|
Service_FS, ///< The FS (Filesystem) service implementation
|
|
|
|
Service_ERR, ///< The ERR (Error) port implementation
|
|
|
|
Service_APT, ///< The APT (Applets) service
|
2016-10-02 09:45:58 +02:00
|
|
|
Service_BOSS, ///< The BOSS (SpotPass) service
|
2016-09-18 02:38:01 +02:00
|
|
|
Service_GSP, ///< The GSP (GPU control) service
|
|
|
|
Service_AC, ///< The AC (WiFi status) service
|
|
|
|
Service_AM, ///< The AM (Application manager) service
|
|
|
|
Service_PTM, ///< The PTM (Power status & misc.) service
|
|
|
|
Service_LDR, ///< The LDR (3ds dll loader) service
|
2016-11-20 06:50:48 +01:00
|
|
|
Service_MIC, ///< The MIC (Microphone) service
|
2016-09-18 02:38:01 +02:00
|
|
|
Service_NDM, ///< The NDM (Network daemon manager) service
|
2016-12-29 21:38:47 +01:00
|
|
|
Service_NFC, ///< The NFC service
|
2016-09-18 02:38:01 +02:00
|
|
|
Service_NIM, ///< The NIM (Network interface manager) service
|
2017-11-06 20:51:57 +01:00
|
|
|
Service_NS, ///< The NS (Nintendo User Interface Shell) service
|
2016-09-18 02:38:01 +02:00
|
|
|
Service_NWM, ///< The NWM (Network wlan manager) service
|
|
|
|
Service_CAM, ///< The CAM (Camera) service
|
|
|
|
Service_CECD, ///< The CECD (StreetPass) service
|
|
|
|
Service_CFG, ///< The CFG (Configuration) service
|
2016-12-08 10:11:54 +01:00
|
|
|
Service_CSND, ///< The CSND (CWAV format process) service
|
2016-09-18 02:38:01 +02:00
|
|
|
Service_DSP, ///< The DSP (DSP control) service
|
|
|
|
Service_DLP, ///< The DLP (Download Play) service
|
|
|
|
Service_HID, ///< The HID (Human interface device) service
|
2017-02-06 18:41:31 +01:00
|
|
|
Service_HTTP, ///< The HTTP service
|
2016-09-18 02:38:01 +02:00
|
|
|
Service_SOC, ///< The SOC (Socket) service
|
|
|
|
Service_IR, ///< The IR service
|
|
|
|
Service_Y2R, ///< The Y2R (YUV to RGB conversion) service
|
2019-04-15 16:56:55 +02:00
|
|
|
Service_PS, ///< The PS (Process) service
|
2016-09-18 02:38:01 +02:00
|
|
|
HW, ///< Low-level hardware emulation
|
|
|
|
HW_Memory, ///< Memory-map and address translation
|
|
|
|
HW_LCD, ///< LCD register emulation
|
|
|
|
HW_GPU, ///< GPU control emulation
|
2017-01-01 13:58:02 +01:00
|
|
|
HW_AES, ///< AES engine emulation
|
2016-09-18 02:38:01 +02:00
|
|
|
Frontend, ///< Emulator UI
|
|
|
|
Render, ///< Emulator video output and hardware acceleration
|
|
|
|
Render_Software, ///< Software renderer backend
|
|
|
|
Render_OpenGL, ///< OpenGL backend
|
|
|
|
Audio, ///< Audio emulation
|
2020-05-04 12:20:56 +02:00
|
|
|
Audio_DSP, ///< The HLE and LLE implementations of the DSP
|
2016-09-18 02:38:01 +02:00
|
|
|
Audio_Sink, ///< Emulator audio output backend
|
|
|
|
Loader, ///< ROM loader
|
2017-01-20 20:52:32 +01:00
|
|
|
Input, ///< Input emulation
|
2017-07-07 21:34:15 +02:00
|
|
|
Network, ///< Network emulation
|
2017-12-17 04:43:09 +01:00
|
|
|
Movie, ///< Movie (Input Recording) Playback
|
2017-06-28 04:29:00 +02:00
|
|
|
WebService, ///< Interface to Citra Web Services
|
2018-09-11 22:00:12 +02:00
|
|
|
RPC_Server, ///< RPC server
|
2016-11-20 06:50:48 +01:00
|
|
|
Count ///< Total number of logging classes
|
2014-10-28 08:36:00 +01:00
|
|
|
};
|
|
|
|
|
2019-07-14 18:20:00 +02:00
|
|
|
/**
|
|
|
|
* Implements a log message filter which allows different log classes to have different minimum
|
|
|
|
* severity levels. The filter can be changed at runtime and can be parsed from a string to allow
|
|
|
|
* editing via the interface or loading from a configuration file.
|
|
|
|
*/
|
|
|
|
class Filter {
|
|
|
|
public:
|
|
|
|
/// Initializes the filter with all classes having `default_level` as the minimum level.
|
|
|
|
explicit Filter(Level default_level = Level::Info);
|
|
|
|
|
|
|
|
/// Resets the filter so that all classes have `level` as the minimum displayed level.
|
|
|
|
void ResetAll(Level level);
|
|
|
|
/// Sets the minimum level of `log_class` (and not of its subclasses) to `level`.
|
|
|
|
void SetClassLevel(Class log_class, Level level);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses a filter string and applies it to this filter.
|
|
|
|
*
|
|
|
|
* A filter string consists of a space-separated list of filter rules, each of the format
|
|
|
|
* `<class>:<level>`. `<class>` is a log class name, with subclasses separated using periods.
|
|
|
|
* `*` is allowed as a class name and will reset all filters to the specified level. `<level>`
|
|
|
|
* a severity level name which will be set as the minimum logging level of the matched classes.
|
|
|
|
* Rules are applied left to right, with each rule overriding previous ones in the sequence.
|
|
|
|
*
|
|
|
|
* A few examples of filter rules:
|
|
|
|
* - `*:Info` -- Resets the level of all classes to Info.
|
|
|
|
* - `Service:Info` -- Sets the level of Service to Info.
|
|
|
|
* - `Service.FS:Trace` -- Sets the level of the Service.FS class to Trace.
|
|
|
|
*/
|
|
|
|
void ParseFilterString(std::string_view filter_view);
|
|
|
|
|
|
|
|
/// Matches class/level combination against the filter, returning true if it passed.
|
|
|
|
bool CheckMessage(Class log_class, Level level) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::array<Level, static_cast<std::size_t>(Class::Count)> class_levels;
|
|
|
|
};
|
|
|
|
extern Filter filter;
|
|
|
|
|
|
|
|
void SetGlobalFilter(const Filter& f);
|
|
|
|
|
2018-03-21 16:36:45 +01:00
|
|
|
/// Logs a message to the global logger, using fmt
|
2018-04-06 06:33:12 +02:00
|
|
|
void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
|
|
|
|
unsigned int line_num, const char* function, const char* format,
|
|
|
|
const fmt::format_args& args);
|
2018-03-21 16:36:45 +01:00
|
|
|
|
2018-03-16 04:48:33 +01:00
|
|
|
template <typename... Args>
|
2018-02-20 01:51:27 +01:00
|
|
|
void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
|
2018-03-16 14:18:45 +01:00
|
|
|
const char* function, const char* format, const Args&... args) {
|
2019-07-14 18:20:00 +02:00
|
|
|
if (!filter.CheckMessage(log_class, log_level))
|
|
|
|
return;
|
|
|
|
|
2018-04-06 06:33:12 +02:00
|
|
|
FmtLogMessageImpl(log_class, log_level, filename, line_num, function, format,
|
2018-07-26 23:31:03 +02:00
|
|
|
fmt::make_format_args(args...));
|
2018-03-16 04:48:33 +01:00
|
|
|
}
|
2018-02-20 01:51:27 +01:00
|
|
|
|
2014-10-28 08:36:00 +01:00
|
|
|
} // namespace Log
|
|
|
|
|
2018-02-20 01:51:27 +01:00
|
|
|
// Define the fmt lib macros
|
2018-06-29 15:56:12 +02:00
|
|
|
#define LOG_GENERIC(log_class, log_level, ...) \
|
2019-12-24 21:19:18 +01:00
|
|
|
::Log::FmtLogMessage(log_class, log_level, ::Log::TrimSourcePath(__FILE__), __LINE__, \
|
|
|
|
__func__, __VA_ARGS__)
|
2018-06-23 00:48:25 +02:00
|
|
|
|
2018-02-20 01:51:27 +01:00
|
|
|
#ifdef _DEBUG
|
2018-06-29 15:56:12 +02:00
|
|
|
#define LOG_TRACE(log_class, ...) \
|
2019-12-24 21:19:18 +01:00
|
|
|
::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Trace, \
|
|
|
|
::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
|
2018-02-20 01:51:27 +01:00
|
|
|
#else
|
2018-06-29 13:18:07 +02:00
|
|
|
#define LOG_TRACE(log_class, fmt, ...) (void(0))
|
2018-02-20 01:51:27 +01:00
|
|
|
#endif
|
|
|
|
|
2018-06-29 15:56:12 +02:00
|
|
|
#define LOG_DEBUG(log_class, ...) \
|
2019-12-24 21:19:18 +01:00
|
|
|
::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Debug, \
|
|
|
|
::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
|
2018-06-29 15:56:12 +02:00
|
|
|
#define LOG_INFO(log_class, ...) \
|
2019-12-24 21:19:18 +01:00
|
|
|
::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Info, \
|
|
|
|
::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
|
2018-06-29 15:56:12 +02:00
|
|
|
#define LOG_WARNING(log_class, ...) \
|
2019-12-24 21:19:18 +01:00
|
|
|
::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Warning, \
|
|
|
|
::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
|
2018-06-29 15:56:12 +02:00
|
|
|
#define LOG_ERROR(log_class, ...) \
|
2019-12-24 21:19:18 +01:00
|
|
|
::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Error, \
|
|
|
|
::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
|
2018-06-29 15:56:12 +02:00
|
|
|
#define LOG_CRITICAL(log_class, ...) \
|
2019-12-24 21:19:18 +01:00
|
|
|
::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Critical, \
|
|
|
|
::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
|