Key control: shortcut to control repeating of msgs

This commit is contained in:
Martin Pulec
2020-11-13 14:42:32 +01:00
parent a0f48ad255
commit b888e09800
3 changed files with 12 additions and 3 deletions

View File

@@ -258,5 +258,5 @@ void Logger::preinit(bool skip_repeated)
}
std::atomic<Logger::last_message *> Logger::last_msg{};
bool Logger::skip_repeated = true;
std::atomic<bool> Logger::skip_repeated{true};

View File

@@ -92,6 +92,8 @@ bool set_log_level(const char *optarg, bool *logger_repeat_msgs);
#include "compat/platform_time.h"
#include "rang.hpp"
class keyboard_control; // friend
// Log, version 0.1: a simple logging class
class Logger
{
@@ -145,12 +147,14 @@ private:
int level;
std::ostringstream oss;
static bool skip_repeated;
static std::atomic<bool> skip_repeated;
struct last_message {
std::string msg;
int count{0};
};
static std::atomic<last_message *> last_msg; // leaks last message upon exit
friend class keyboard_control;
};
#define LOG(level) \

View File

@@ -121,7 +121,7 @@ keyboard_control::keyboard_control(struct module *parent) :
m_should_exit(false),
m_started(false),
m_locked_against_changes(true),
guarded_keys { '*', '/', '9', '0', 'c', 'C', 'm', 'M', '>', '<', 'e', 's', 'S', 'v', 'V' }
guarded_keys { '*', '/', '9', '0', 'c', 'C', 'm', 'M', '>', '<', 'e', 's', 'S', 'v', 'V', 'r' }
{
m_start_time = time(NULL);
@@ -540,6 +540,10 @@ void keyboard_control::run()
cout << "Log level: " << log_level << "\n";
break;
}
case 'r':
Logger::skip_repeated = !Logger::skip_repeated;
cout << "Skip repeated messages: " << std::boolalpha << Logger::skip_repeated << std::noboolalpha << "\n";
break;
case 's':
if (saved_log_level == -1) {
saved_log_level = log_level;
@@ -672,6 +676,7 @@ void keyboard_control::usage()
BOLD("\t M ") << "- mute/unmute sender" << G('M') << "\n" <<
BOLD("\t v ") << "- increase verbosity level" << G('v') << "\n" <<
BOLD("\t V ") << "- decrease verbosity level" << G('V') << "\n" <<
BOLD("\t r ") << "- skip repeated messages (toggle) " << G('r') << "\n" <<
BOLD("\t e ") << "- record captured content (toggle)" << G('e') << "\n" <<
BOLD("\t h ") << "- show help" << G('h') << "\n" <<
BOLD("\t i ") << "- show various information" << G('i') << "\n" <<