From f97e40f127441828eb4ffe11841ebf79191ac8a3 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 22 Jul 2020 22:35:40 -0400 Subject: moved initLogging() to loglist.cpp --- src/loglist.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/loglist.h | 3 +++ src/main.cpp | 67 ++------------------------------------------------------- 3 files changed, 70 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/loglist.cpp b/src/loglist.cpp index a4868ed4..7a64ecad 100644 --- a/src/loglist.cpp +++ b/src/loglist.cpp @@ -262,3 +262,68 @@ void LogList::onContextMenu(const QPoint& pos) auto* menu = createMenu(this); menu->popup(viewport()->mapToGlobal(pos)); } + + +log::Levels convertQtLevel(QtMsgType t) +{ + switch (t) + { + case QtDebugMsg: + return log::Debug; + + case QtWarningMsg: + return log::Warning; + + case QtCriticalMsg: // fall-through + case QtFatalMsg: + return log::Error; + + case QtInfoMsg: // fall-through + default: + return log::Info; + } +} + +void qtLogCallback( + QtMsgType type, const QMessageLogContext& context, const QString& message) +{ + std::string_view file = ""; + + if (type != QtDebugMsg) { + if (context.file) { + file = context.file; + + const auto lastSep = file.find_last_of("/\\"); + if (lastSep != std::string_view::npos) { + file = {context.file + lastSep + 1}; + } + } + } + + if (file.empty()) { + log::log( + convertQtLevel(type), "{}", + message.toStdString()); + } else { + log::log( + convertQtLevel(type), "[{}:{}] {}", + file, context.line, message.toStdString()); + } +} + +void initLogging() +{ + LogModel::create(); + + log::LoggerConfiguration conf; + conf.maxLevel = MOBase::log::Debug; + conf.pattern = "%^[%Y-%m-%d %H:%M:%S.%e %L] %v%$"; + conf.utc = true; + + log::createDefault(conf); + + log::getDefault().setCallback( + [](log::Entry e){ LogModel::instance().add(e); }); + + qInstallMessageHandler(qtLogCallback); +} diff --git a/src/loglist.h b/src/loglist.h index 6b3aa4d5..7387eb50 100644 --- a/src/loglist.h +++ b/src/loglist.h @@ -82,4 +82,7 @@ private: void onNewEntry(); }; + +void initLogging(); + #endif // LOGBUFFER_H diff --git a/src/main.cpp b/src/main.cpp index a335a37a..e52b252b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -599,71 +599,6 @@ int runApplication( return 1; } -log::Levels convertQtLevel(QtMsgType t) -{ - switch (t) - { - case QtDebugMsg: - return log::Debug; - - case QtWarningMsg: - return log::Warning; - - case QtCriticalMsg: // fall-through - case QtFatalMsg: - return log::Error; - - case QtInfoMsg: // fall-through - default: - return log::Info; - } -} - -void qtLogCallback( - QtMsgType type, const QMessageLogContext& context, const QString& message) -{ - std::string_view file = ""; - - if (type != QtDebugMsg) { - if (context.file) { - file = context.file; - - const auto lastSep = file.find_last_of("/\\"); - if (lastSep != std::string_view::npos) { - file = {context.file + lastSep + 1}; - } - } - } - - if (file.empty()) { - log::log( - convertQtLevel(type), "{}", - message.toStdString()); - } else { - log::log( - convertQtLevel(type), "[{}:{}] {}", - file, context.line, message.toStdString()); - } -} - -void initLogging() -{ - LogModel::create(); - - log::LoggerConfiguration conf; - conf.maxLevel = MOBase::log::Debug; - conf.pattern = "%^[%Y-%m-%d %H:%M:%S.%e %L] %v%$"; - conf.utc = true; - - log::createDefault(conf); - - log::getDefault().setCallback( - [](log::Entry e){ LogModel::instance().add(e); }); - - qInstallMessageHandler(qtLogCallback); -} - - int main(int argc, char *argv[]) { cl::CommandLine cl; @@ -673,6 +608,8 @@ int main(int argc, char *argv[]) return *r; TimeThis tt("main to runApplication()"); + + // in loglist.cpp initLogging(); //Make sure the configured temp folder exists -- cgit v1.3.1