Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10871 from shuffle2/logging
logging improvements
  • Loading branch information
AdmiralCurtiss committed Jul 18, 2022
2 parents f43fa8a + 2882843 commit dd67d5f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 8 additions & 2 deletions Source/Core/AudioCommon/CubebUtils.cpp
Expand Up @@ -22,6 +22,10 @@ static void LogCallback(const char* format, ...)
if (instance == nullptr)
return;

constexpr auto log_type = Common::Log::LogType::AUDIO;
if (!instance->IsEnabled(log_type))
return;

va_list args;
va_start(args, format);
const char* filename = va_arg(args, const char*) + s_path_cutoff_point;
Expand All @@ -30,8 +34,8 @@ static void LogCallback(const char* format, ...)
const std::string message = StringFromFormatV(adapted_format.c_str(), args);
va_end(args);

instance->Log(Common::Log::LogLevel::LNOTICE, Common::Log::LogType::AUDIO, filename, lineno,
message.c_str());
instance->LogWithFullPath(Common::Log::LogLevel::LNOTICE, log_type, filename, lineno,
message.c_str());
}

static void DestroyContext(cubeb* ctx)
Expand All @@ -54,6 +58,8 @@ std::shared_ptr<cubeb> CubebUtils::GetContext()

const char* filename = __FILE__;
const char* match_point = strstr(filename, DIR_SEP "Source" DIR_SEP "Core" DIR_SEP);
if (!match_point)
match_point = strstr(filename, R"(\Source\Core\)");
if (match_point)
{
s_path_cutoff_point = match_point - filename + strlen(DIR_SEP "Externals" DIR_SEP);
Expand Down
5 changes: 2 additions & 3 deletions Source/Core/Common/Logging/LogManager.h
Expand Up @@ -39,6 +39,8 @@ class LogManager
static void Shutdown();

void Log(LogLevel level, LogType type, const char* file, int line, const char* message);
void LogWithFullPath(LogLevel level, LogType type, const char* file, int line,
const char* message);

LogLevel GetLogLevel() const;
void SetLogLevel(LogLevel level);
Expand Down Expand Up @@ -73,9 +75,6 @@ class LogManager
LogManager(LogManager&&) = delete;
LogManager& operator=(LogManager&&) = delete;

void LogWithFullPath(LogLevel level, LogType type, const char* file, int line,
const char* message);

LogLevel m_level;
EnumMap<LogContainer, LogType::WIIMOTE> m_log{};
std::array<LogListener*, LogListener::NUMBER_OF_LISTENERS> m_listeners{};
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Config/LogWidget.cpp
Expand Up @@ -102,7 +102,7 @@ void LogWidget::UpdateLog()
const std::string_view str_view(std::get<std::string>(line));

m_log_text->appendHtml(
QStringLiteral("%1 <span style=\"color: %2; white-space: pre\">%3</span>")
QStringLiteral("%1<span style=\"color: %2; white-space: pre\">%3</span>")
.arg(QStringFromStringView(str_view.substr(0, TIMESTAMP_LENGTH)),
QString::fromUtf8(color),
QStringFromStringView(str_view.substr(TIMESTAMP_LENGTH)).toHtmlEscaped()));
Expand Down

0 comments on commit dd67d5f

Please sign in to comment.