Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate consecutive duplicate logger lines #1304

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.vscode
.vs
.idea
.kdev4
*.kdev4
/[Bb]uild

# Ignore executables (Linux, macOS, Windows)
Expand Down
16 changes: 15 additions & 1 deletion src/Core/Misc/PlogLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#ifdef _WIN32
#include <cstdio>
#include <cstring>

namespace plog {

/**
Expand Down Expand Up @@ -84,7 +86,19 @@ PlogLogger::PlogLogger() {
}

void PlogLogger::log(Core::ILogger::Severity logLevel, const std::string_view message) {
PLOG(PlogLogger::convertSeverity(logLevel)) << message;
const std::lock_guard<std::mutex> lock(this->mutex);
if (this->last_msg.empty()) {
StarbotArc marked this conversation as resolved.
Show resolved Hide resolved
if (message == this->last_msg) {
this->count++;
} else {
PLOG(PlogLogger::convertSeverity(logLevel)) << this->last_msg << (this->count > 0? fmt::format(FMT_STRING(" (x{})"), std::to_string(this->count + 1)) : "");

this->last_msg = std::string{message};
this->count = 0;
}
} else {
this->last_msg = std::string{message};
}
}

void PlogLogger::setLogLevel(Core::ILogger::Severity logLevel) {
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Misc/PlogLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
#include "Core/Services/ILogger.hpp"
#include <plog/Log.h>

#include <mutex>

class PlogLogger : public Core::ILogger {
public:
int count = 0;
std::string last_msg;
std::mutex mutex;

PlogLogger();
void setLogLevel(ILogger::Severity logLevel) override;
std::string getLogFile() override;
Expand Down
2 changes: 2 additions & 0 deletions src/RageUtil/File/RageFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#ifndef RAGE_FILE_H
#define RAGE_FILE_H

#include <cstdint>

#include "RageFileBasic.h"

struct lua_State;
Expand Down
Loading