summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-07-22 22:35:40 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2020-11-03 11:39:02 -0500
commitf97e40f127441828eb4ffe11841ebf79191ac8a3 (patch)
treedb6bc99a64b02069eff6966040e10c7211fc83c3 /src
parent3d1d9f111025879983147fbbe78f8af04693d066 (diff)
moved initLogging() to loglist.cpp
Diffstat (limited to 'src')
-rw-r--r--src/loglist.cpp65
-rw-r--r--src/loglist.h3
-rw-r--r--src/main.cpp67
3 files changed, 70 insertions, 65 deletions
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