Skip to content

Commit

Permalink
♻️ Completely abstract HotReload::log msg
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierLDff committed Jul 15, 2021
1 parent 76d06fa commit ecffec6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
19 changes: 18 additions & 1 deletion src/Qaterial/HotReload/HotReload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,24 @@ void HotReload::resetImportPath() { _resetImportPath = true; }

void HotReload::log(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
for(auto* hr: hotReloaders) { Q_EMIT hr->newLog(msg); }
// todo : better log ui
const auto timestamp = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
const auto category = [type]() -> QString
{
switch(type)
{
case QtDebugMsg: return "debug";
case QtWarningMsg: return "warning";
case QtCriticalMsg: return "error";
case QtFatalMsg: return "error";
case QtInfoMsg: return "info";
default: return "unknown";
}
}();

const auto log = "[" + timestamp + "] [" + context.category + "] [" + category + "] : " + msg;

for(auto* hr: hotReloaders) { Q_EMIT hr->newLog(log); }
}

void HotReload::watchFile(const QString& path) { _watcher.addPath(path); }
Expand Down
37 changes: 20 additions & 17 deletions src/Qaterial/HotReloadApp/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,31 @@

void qtMsgOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
const auto timestamp = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
const auto category = [type]() -> QString
qaterial::HotReload::log(type, context, msg);

{
switch(type)
const auto timestamp = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
const auto category = [type]() -> QString
{
case QtDebugMsg: return "debug";
case QtWarningMsg: return "warning";
case QtCriticalMsg: return "error";
case QtFatalMsg: return "error";
case QtInfoMsg: return "info";
default: return "unknown";
}
}();

const auto log = "[" + timestamp + "] [" + context.category + "] [" + category + "] : " + msg;
qaterial::HotReload::log(type, context, log);
switch(type)
{
case QtDebugMsg: return "debug";
case QtWarningMsg: return "warning";
case QtCriticalMsg: return "error";
case QtFatalMsg: return "error";
case QtInfoMsg: return "info";
default: return "unknown";
}
}();

const auto log = "[" + timestamp + "] [" + context.category + "] [" + category + "] : " + msg;
#if defined(Q_OS_WIN)
const auto winLog = log + "\n";
OutputDebugStringW(reinterpret_cast<const wchar_t*>(winLog.utf16()));
const auto winLog = log + "\n";
OutputDebugStringW(reinterpret_cast<const wchar_t*>(winLog.utf16()));
#elif defined(Q_OS_ANDROID)
android_default_message_handler(type, context, msg);
android_default_message_handler(type, context, msg);
#endif
}
}

int main(int argc, char* argv[])
Expand Down

0 comments on commit ecffec6

Please sign in to comment.