Common: Unify logging namespace with Common

Previously the logging was a in a little bit of a disarray. Some things
were in namespaces, and other things were not.

Given this code will feature a bit of restructuring during the
transition over to fmt, this is a good time to unify it under a single
namespace and also remove functions and types from the global namespace.

Now, all functions and types are under the Common::Log namespace. The
only outliers being, of course, the preprocessor macros.
This commit is contained in:
Lioncash
2019-11-28 04:19:24 -05:00
parent c2c8a14966
commit c792961000
42 changed files with 261 additions and 245 deletions

View File

@ -62,11 +62,12 @@ void LogConfigWidget::CreateWidgets()
m_types_toggle = new QPushButton(tr("Toggle All Log Types"));
m_types_list = new QListWidget;
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
const auto* const log_manager = Common::Log::LogManager::GetInstance();
for (int i = 0; i < Common::Log::NUMBER_OF_LOGS; i++)
{
const auto log_type = static_cast<LogTypes::LOG_TYPE>(i);
const QString full_name = QString::fromUtf8(LogManager::GetInstance()->GetFullName(log_type));
const QString short_name = QString::fromUtf8(LogManager::GetInstance()->GetShortName(log_type));
const auto log_type = static_cast<Common::Log::LOG_TYPE>(i);
const QString full_name = QString::fromUtf8(log_manager->GetFullName(log_type));
const QString short_name = QString::fromUtf8(log_manager->GetShortName(log_type));
auto* widget = new QListWidgetItem(QStringLiteral("%1 (%2)").arg(full_name, short_name));
widget->setCheckState(Qt::Unchecked);
m_types_list->addItem(widget);
@ -77,7 +78,7 @@ void LogConfigWidget::CreateWidgets()
verbosity_layout->addWidget(m_verbosity_error);
verbosity_layout->addWidget(m_verbosity_warning);
verbosity_layout->addWidget(m_verbosity_info);
if (MAX_LOGLEVEL == LogTypes::LOG_LEVELS::LDEBUG)
if constexpr (MAX_LOGLEVEL == Common::Log::LOG_LEVELS::LDEBUG)
{
verbosity_layout->addWidget(m_verbosity_debug);
}
@ -132,29 +133,32 @@ void LogConfigWidget::ConnectWidgets()
void LogConfigWidget::LoadSettings()
{
auto* logmanager = LogManager::GetInstance();
auto& settings = Settings::GetQSettings();
const auto* const log_manager = Common::Log::LogManager::GetInstance();
const auto& settings = Settings::GetQSettings();
restoreGeometry(settings.value(QStringLiteral("logconfigwidget/geometry")).toByteArray());
setFloating(settings.value(QStringLiteral("logconfigwidget/floating")).toBool());
// Config - Verbosity
const LogTypes::LOG_LEVELS verbosity = logmanager->GetLogLevel();
m_verbosity_notice->setChecked(verbosity == LogTypes::LOG_LEVELS::LNOTICE);
m_verbosity_error->setChecked(verbosity == LogTypes::LOG_LEVELS::LERROR);
m_verbosity_warning->setChecked(verbosity == LogTypes::LOG_LEVELS::LWARNING);
m_verbosity_info->setChecked(verbosity == LogTypes::LOG_LEVELS::LINFO);
m_verbosity_debug->setChecked(verbosity == LogTypes::LOG_LEVELS::LDEBUG);
const Common::Log::LOG_LEVELS verbosity = log_manager->GetLogLevel();
m_verbosity_notice->setChecked(verbosity == Common::Log::LOG_LEVELS::LNOTICE);
m_verbosity_error->setChecked(verbosity == Common::Log::LOG_LEVELS::LERROR);
m_verbosity_warning->setChecked(verbosity == Common::Log::LOG_LEVELS::LWARNING);
m_verbosity_info->setChecked(verbosity == Common::Log::LOG_LEVELS::LINFO);
m_verbosity_debug->setChecked(verbosity == Common::Log::LOG_LEVELS::LDEBUG);
// Config - Outputs
m_out_file->setChecked(logmanager->IsListenerEnabled(LogListener::FILE_LISTENER));
m_out_console->setChecked(logmanager->IsListenerEnabled(LogListener::CONSOLE_LISTENER));
m_out_window->setChecked(logmanager->IsListenerEnabled(LogListener::LOG_WINDOW_LISTENER));
m_out_file->setChecked(log_manager->IsListenerEnabled(Common::Log::LogListener::FILE_LISTENER));
m_out_console->setChecked(
log_manager->IsListenerEnabled(Common::Log::LogListener::CONSOLE_LISTENER));
m_out_window->setChecked(
log_manager->IsListenerEnabled(Common::Log::LogListener::LOG_WINDOW_LISTENER));
// Config - Log Types
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
for (int i = 0; i < Common::Log::NUMBER_OF_LOGS; ++i)
{
bool log_enabled = LogManager::GetInstance()->IsEnabled(static_cast<LogTypes::LOG_TYPE>(i));
const auto log_type = static_cast<Common::Log::LOG_TYPE>(i);
const bool log_enabled = log_manager->IsEnabled(log_type);
if (!log_enabled)
m_all_enabled = false;
@ -174,41 +178,43 @@ void LogConfigWidget::SaveSettings()
settings.setValue(QStringLiteral("logconfigwidget/floating"), isFloating());
// Config - Verbosity
LogTypes::LOG_LEVELS verbosity = LogTypes::LOG_LEVELS::LNOTICE;
auto verbosity = Common::Log::LOG_LEVELS::LNOTICE;
if (m_verbosity_notice->isChecked())
verbosity = LogTypes::LOG_LEVELS::LNOTICE;
verbosity = Common::Log::LOG_LEVELS::LNOTICE;
if (m_verbosity_error->isChecked())
verbosity = LogTypes::LOG_LEVELS::LERROR;
verbosity = Common::Log::LOG_LEVELS::LERROR;
if (m_verbosity_warning->isChecked())
verbosity = LogTypes::LOG_LEVELS::LWARNING;
verbosity = Common::Log::LOG_LEVELS::LWARNING;
if (m_verbosity_info->isChecked())
verbosity = LogTypes::LOG_LEVELS::LINFO;
verbosity = Common::Log::LOG_LEVELS::LINFO;
if (m_verbosity_debug->isChecked())
verbosity = LogTypes::LOG_LEVELS::LDEBUG;
verbosity = Common::Log::LOG_LEVELS::LDEBUG;
auto* const log_manager = Common::Log::LogManager::GetInstance();
// Config - Verbosity
LogManager::GetInstance()->SetLogLevel(verbosity);
log_manager->SetLogLevel(verbosity);
// Config - Outputs
LogManager::GetInstance()->EnableListener(LogListener::FILE_LISTENER, m_out_file->isChecked());
LogManager::GetInstance()->EnableListener(LogListener::CONSOLE_LISTENER,
m_out_console->isChecked());
LogManager::GetInstance()->EnableListener(LogListener::LOG_WINDOW_LISTENER,
m_out_window->isChecked());
log_manager->EnableListener(Common::Log::LogListener::FILE_LISTENER, m_out_file->isChecked());
log_manager->EnableListener(Common::Log::LogListener::CONSOLE_LISTENER,
m_out_console->isChecked());
log_manager->EnableListener(Common::Log::LogListener::LOG_WINDOW_LISTENER,
m_out_window->isChecked());
// Config - Log Types
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
for (int i = 0; i < Common::Log::NUMBER_OF_LOGS; ++i)
{
const auto type = static_cast<LogTypes::LOG_TYPE>(i);
bool enabled = m_types_list->item(i)->checkState() == Qt::Checked;
bool was_enabled = LogManager::GetInstance()->IsEnabled(type);
const auto type = static_cast<Common::Log::LOG_TYPE>(i);
const bool enabled = m_types_list->item(i)->checkState() == Qt::Checked;
const bool was_enabled = log_manager->IsEnabled(type);
if (enabled != was_enabled)
LogManager::GetInstance()->SetEnable(type, enabled);
log_manager->SetEnable(type, enabled);
}
}