Add LL_DIALOG log level, which can trigger the GUI to show a message box containing the log message

This commit is contained in:
Adam Honse 2021-11-07 11:41:20 -06:00
parent 695ff3c8a0
commit f1e7ea298f
6 changed files with 71 additions and 88 deletions

View file

@ -9,7 +9,7 @@
#include "filesystem.h"
const char* LogManager::log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "Verbose:", "Debug:", "Trace:"};
const char* LogManager::log_codes[] = {"FATAL:", "ERROR:", "Warning:", "Info:", "Verbose:", "Debug:", "Trace:", "Dialog:"};
LogManager::LogManager()
{
@ -154,7 +154,7 @@ void LogManager::_flush()
{
for(size_t msg = 0; msg < temp_messages.size(); ++msg)
{
if(temp_messages[msg]->level <= loglevel)
if(temp_messages[msg]->level <= loglevel || temp_messages[msg]->level == LL_DIALOG)
{
// Put the timestamp here
std::chrono::milliseconds counter = std::chrono::duration_cast<std::chrono::milliseconds>(temp_messages[msg]->counted_second);
@ -225,12 +225,24 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
mes->line = line;
mes->counted_second = std::chrono::steady_clock::now() - base_clock;
/*-------------------------------------------------*\
| If this is a dialog message, call the dialog show |
| callback |
\*-------------------------------------------------*/
if(level == LL_DIALOG)
{
for(size_t idx = 0; idx < dialog_show_callbacks.size(); idx++)
{
dialog_show_callbacks[idx](dialog_show_callback_args[idx], mes);
}
}
/*-------------------------------------------------*\
| If the message is within the current verbosity, |
| print it on the screen |
| TODO: Put the timestamp here |
\*-------------------------------------------------*/
if(level <= verbosity)
if(level <= verbosity || level == LL_DIALOG)
{
std::cout << mes->buffer;
if(print_source)
@ -254,21 +266,6 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
| Flush the queues |
\*-------------------------------------------------*/
_flush();
/*-------------------------------------------------*\
| If the message level is LL_WARNING or lower, add |
| it to the error queue |
| |
| Commented out - It is causing OpenRGB to crash |
| according to #1537 |
\*-------------------------------------------------*/
//if(level <= LL_WARNING)
//{
// for(size_t idx = 0; idx < error_callbacks.size(); ++idx)
// {
// error_callbacks[idx].first(error_callbacks[idx].second, mes);
// }
//}
}
std::vector<PLogMessage> LogManager::messages()
@ -337,22 +334,21 @@ void LogManager::setPrintSource(bool v)
print_source = v;
}
void LogManager::registerErrorCallback(LogErrorCallback callback, void* receiver)
void LogManager::RegisterDialogShowCallback(LogDialogShowCallback callback, void* receiver)
{
std::lock_guard<std::mutex> grd(entry_mutex);
error_callbacks.push_back(LogErrorBlock(callback, receiver));
LOG_DEBUG("dialog show callback registered");
dialog_show_callbacks.push_back(callback);
dialog_show_callback_args.push_back(receiver);
}
void LogManager::unregisterErrorCallback(LogErrorCallback callback, void* receiver)
void LogManager::UnregisterDialogShowCallback(LogDialogShowCallback callback, void* receiver)
{
std::lock_guard<std::mutex> grd(entry_mutex);
for(size_t idx = 0; idx < error_callbacks.size(); ++idx)
for(size_t idx = 0; idx < dialog_show_callbacks.size(); idx++)
{
if(error_callbacks[idx].first == callback && error_callbacks[idx].second == receiver)
if(dialog_show_callbacks[idx] == callback && dialog_show_callback_args[idx] == receiver)
{
error_callbacks.erase(error_callbacks.begin() + idx);
dialog_show_callbacks.erase(dialog_show_callbacks.begin() + idx);
dialog_show_callback_args.erase(dialog_show_callback_args.begin() + idx);
}
}
}
}