chore: make yuzu REUSE compliant
[REUSE] is a specification that aims at making file copyright
information consistent, so that it can be both human and machine
readable. It basically requires that all files have a header containing
copyright and licensing information. When this isn't possible, like
when dealing with binary assets, generated files or embedded third-party
dependencies, it is permitted to insert copyright information in the
`.reuse/dep5` file.
Oh, and it also requires that all the licenses used in the project are
present in the `LICENSES` folder, that's why the diff is so huge.
This can be done automatically with `reuse download --all`.
The `reuse` tool also contains a handy subcommand that analyzes the
project and tells whether or not the project is (still) compliant,
`reuse lint`.
Following REUSE has a few advantages over the current approach:
- Copyright information is easy to access for users / downstream
- Files like `dist/license.md` do not need to exist anymore, as
`.reuse/dep5` is used instead
- `reuse lint` makes it easy to ensure that copyright information of
files like binary assets / images is always accurate and up to date
To add copyright information of files that didn't have it I looked up
who committed what and when, for each file. As yuzu contributors do not
have to sign a CLA or similar I couldn't assume that copyright ownership
was of the "yuzu Emulator Project", so I used the name and/or email of
the commit author instead.
[REUSE]: https://reuse.software
Follow-up to 01cf05bc75b1e47beb08937439f3ed9339e7b254
2022-05-14 20:06:02 -04:00
|
|
|
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-10-28 03:36:00 -04:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <cstdio>
|
|
|
|
|
2014-11-03 22:42:34 -05:00
|
|
|
#ifdef _WIN32
|
2016-12-03 15:08:02 -05:00
|
|
|
#include <windows.h>
|
2014-11-03 22:42:34 -05:00
|
|
|
#endif
|
|
|
|
|
2022-12-18 02:31:09 -05:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include <android/log.h>
|
|
|
|
#endif
|
|
|
|
|
2016-09-20 11:21:23 -04:00
|
|
|
#include "common/assert.h"
|
2021-06-13 10:31:47 -04:00
|
|
|
#include "common/logging/filter.h"
|
2014-10-28 03:36:00 -04:00
|
|
|
#include "common/logging/log.h"
|
2021-09-30 16:11:47 -04:00
|
|
|
#include "common/logging/log_entry.h"
|
2014-10-28 03:36:00 -04:00
|
|
|
#include "common/logging/text_formatter.h"
|
2014-11-04 00:03:19 -05:00
|
|
|
|
2021-04-14 20:19:52 -04:00
|
|
|
namespace Common::Log {
|
2014-10-28 03:36:00 -04:00
|
|
|
|
2018-03-22 06:21:29 -04:00
|
|
|
std::string FormatLogMessage(const Entry& entry) {
|
2016-09-17 20:38:01 -04:00
|
|
|
unsigned int time_seconds = static_cast<unsigned int>(entry.timestamp.count() / 1000000);
|
2014-10-28 03:36:00 -04:00
|
|
|
unsigned int time_fractional = static_cast<unsigned int>(entry.timestamp.count() % 1000000);
|
|
|
|
|
2015-05-12 01:19:44 -04:00
|
|
|
const char* class_name = GetLogClassName(entry.log_class);
|
|
|
|
const char* level_name = GetLevelName(entry.log_level);
|
2014-10-28 03:36:00 -04:00
|
|
|
|
2018-03-22 06:21:29 -04:00
|
|
|
return fmt::format("[{:4d}.{:06d}] {} <{}> {}:{}:{}: {}", time_seconds, time_fractional,
|
|
|
|
class_name, level_name, entry.filename, entry.function, entry.line_num,
|
|
|
|
entry.message);
|
2014-10-28 03:36:00 -04:00
|
|
|
}
|
|
|
|
|
2014-12-13 23:09:56 -05:00
|
|
|
void PrintMessage(const Entry& entry) {
|
2018-10-04 23:55:50 -04:00
|
|
|
const auto str = FormatLogMessage(entry).append(1, '\n');
|
2018-03-22 06:21:29 -04:00
|
|
|
fputs(str.c_str(), stderr);
|
2014-12-13 23:09:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintColoredMessage(const Entry& entry) {
|
2014-11-03 22:42:34 -05:00
|
|
|
#ifdef _WIN32
|
2018-03-22 06:21:29 -04:00
|
|
|
HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE);
|
|
|
|
if (console_handle == INVALID_HANDLE_VALUE) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-03 22:42:34 -05:00
|
|
|
|
2018-08-21 11:28:25 -04:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO original_info = {};
|
2014-12-13 23:09:56 -05:00
|
|
|
GetConsoleScreenBufferInfo(console_handle, &original_info);
|
|
|
|
|
2014-11-03 22:42:34 -05:00
|
|
|
WORD color = 0;
|
2014-12-13 23:09:56 -05:00
|
|
|
switch (entry.log_level) {
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Trace: // Grey
|
2016-09-17 20:38:01 -04:00
|
|
|
color = FOREGROUND_INTENSITY;
|
|
|
|
break;
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Debug: // Cyan
|
2016-09-17 20:38:01 -04:00
|
|
|
color = FOREGROUND_GREEN | FOREGROUND_BLUE;
|
|
|
|
break;
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Info: // Bright gray
|
2016-09-17 20:38:01 -04:00
|
|
|
color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
|
|
|
break;
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Warning: // Bright yellow
|
2016-09-17 20:38:01 -04:00
|
|
|
color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
|
|
|
break;
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Error: // Bright red
|
2016-09-17 20:38:01 -04:00
|
|
|
color = FOREGROUND_RED | FOREGROUND_INTENSITY;
|
|
|
|
break;
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Critical: // Bright magenta
|
2016-09-17 20:38:01 -04:00
|
|
|
color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
|
|
|
break;
|
2015-08-02 12:55:31 -04:00
|
|
|
case Level::Count:
|
2015-08-02 18:30:24 -04:00
|
|
|
UNREACHABLE();
|
2014-11-03 22:42:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SetConsoleTextAttribute(console_handle, color);
|
|
|
|
#else
|
2016-09-17 20:38:01 -04:00
|
|
|
#define ESC "\x1b"
|
2014-11-03 22:42:34 -05:00
|
|
|
const char* color = "";
|
2014-12-13 23:09:56 -05:00
|
|
|
switch (entry.log_level) {
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Trace: // Grey
|
2016-09-17 20:38:01 -04:00
|
|
|
color = ESC "[1;30m";
|
|
|
|
break;
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Debug: // Cyan
|
2016-09-17 20:38:01 -04:00
|
|
|
color = ESC "[0;36m";
|
|
|
|
break;
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Info: // Bright gray
|
2016-09-17 20:38:01 -04:00
|
|
|
color = ESC "[0;37m";
|
|
|
|
break;
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Warning: // Bright yellow
|
2016-09-17 20:38:01 -04:00
|
|
|
color = ESC "[1;33m";
|
|
|
|
break;
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Error: // Bright red
|
2016-09-17 20:38:01 -04:00
|
|
|
color = ESC "[1;31m";
|
|
|
|
break;
|
2014-11-03 22:42:34 -05:00
|
|
|
case Level::Critical: // Bright magenta
|
2016-09-17 20:38:01 -04:00
|
|
|
color = ESC "[1;35m";
|
|
|
|
break;
|
2015-08-02 12:55:31 -04:00
|
|
|
case Level::Count:
|
2015-08-02 18:30:24 -04:00
|
|
|
UNREACHABLE();
|
2014-11-03 22:42:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs(color, stderr);
|
|
|
|
#endif
|
|
|
|
|
2014-12-13 23:09:56 -05:00
|
|
|
PrintMessage(entry);
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
SetConsoleTextAttribute(console_handle, original_info.wAttributes);
|
|
|
|
#else
|
|
|
|
fputs(ESC "[0m", stderr);
|
2016-09-17 20:38:01 -04:00
|
|
|
#undef ESC
|
2014-12-13 23:09:56 -05:00
|
|
|
#endif
|
2014-10-28 03:36:00 -04:00
|
|
|
}
|
2022-12-18 02:31:09 -05:00
|
|
|
|
|
|
|
void PrintMessageToLogcat(const Entry& entry) {
|
|
|
|
#ifdef ANDROID
|
|
|
|
const auto str = FormatLogMessage(entry);
|
|
|
|
|
|
|
|
android_LogPriority android_log_priority;
|
|
|
|
switch (entry.log_level) {
|
|
|
|
case Level::Trace:
|
|
|
|
android_log_priority = ANDROID_LOG_VERBOSE;
|
|
|
|
break;
|
|
|
|
case Level::Debug:
|
|
|
|
android_log_priority = ANDROID_LOG_DEBUG;
|
|
|
|
break;
|
|
|
|
case Level::Info:
|
|
|
|
android_log_priority = ANDROID_LOG_INFO;
|
|
|
|
break;
|
|
|
|
case Level::Warning:
|
|
|
|
android_log_priority = ANDROID_LOG_WARN;
|
|
|
|
break;
|
|
|
|
case Level::Error:
|
|
|
|
android_log_priority = ANDROID_LOG_ERROR;
|
|
|
|
break;
|
|
|
|
case Level::Critical:
|
|
|
|
android_log_priority = ANDROID_LOG_FATAL;
|
|
|
|
break;
|
|
|
|
case Level::Count:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2023-03-21 21:41:22 -04:00
|
|
|
__android_log_print(android_log_priority, "YuzuNative", "%s", str.c_str());
|
2022-12-18 02:31:09 -05:00
|
|
|
#endif
|
|
|
|
}
|
2021-04-14 20:19:52 -04:00
|
|
|
} // namespace Common::Log
|