ExecuteFilter: Add timestamps to command outputs

By adding a new function to MessageManager.

Change-Id: Ia70d781c0398e8ce0a055ae8fc4718a9081e688f
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Andre Hartmann
2020-02-20 13:38:43 +01:00
committed by André Hartmann
parent b14351dab8
commit 32935591dd
3 changed files with 12 additions and 4 deletions

View File

@@ -134,7 +134,7 @@ void ExecuteFilter::finished(int exitCode, QProcess::ExitStatus status)
message = tr("Command \"%1\" finished.").arg(commandName);
else
message = tr("Command \"%1\" failed.").arg(commandName);
MessageManager::write(message);
MessageManager::writeWithTime(message);
m_taskQueue.dequeue();
if (!m_taskQueue.isEmpty())
@@ -162,18 +162,18 @@ void ExecuteFilter::runHeadCommand()
const ExecuteData &d = m_taskQueue.head();
const Utils::FilePath fullPath = Utils::Environment::systemEnvironment().searchInPath(d.executable);
if (fullPath.isEmpty()) {
MessageManager::write(tr("Could not find executable for \"%1\".").arg(d.executable));
MessageManager::writeWithTime(tr("Could not find executable for \"%1\".").arg(d.executable));
m_taskQueue.dequeue();
runHeadCommand();
return;
}
MessageManager::write(tr("Starting command \"%1\".").arg(headCommand()));
MessageManager::writeWithTime(tr("Starting command \"%1\".").arg(headCommand()));
m_process->setWorkingDirectory(d.workingDirectory);
m_process->setCommand({fullPath, d.arguments, Utils::CommandLine::Raw});
m_process->start();
m_process->closeWriteChannel();
if (!m_process->waitForStarted(1000)) {
MessageManager::write(tr("Could not start process: %1.").arg(m_process->errorString()));
MessageManager::writeWithTime(tr("Could not start process: %1.").arg(m_process->errorString()));
m_taskQueue.dequeue();
runHeadCommand();
}

View File

@@ -32,6 +32,7 @@
#include <QFont>
#include <QThread>
#include <QTime>
#include <QTimer>
using namespace Core;
@@ -106,6 +107,12 @@ void MessageManager::write(const QString &text, PrintToOutputPaneFlags flags)
QTimer::singleShot(0, instance(), [text, flags] { doWrite(text, flags); });
}
void MessageManager::writeWithTime(const QString &text, PrintToOutputPaneFlags flags)
{
const QString timeStamp = QTime::currentTime().toString("HH:mm:ss ");
write(timeStamp + text, flags);
}
void MessageManager::doWrite(const QString &text, PrintToOutputPaneFlags flags)
{
QTC_ASSERT(m_messageOutputWindow, return);

View File

@@ -65,6 +65,7 @@ public:
static void writeMessages(const QStringList &messages,
PrintToOutputPaneFlags flags = NoModeSwitch);
static void write(const QString &text, PrintToOutputPaneFlags flags = NoModeSwitch);
static void writeWithTime(const QString &text, PrintToOutputPaneFlags flags = NoModeSwitch);
private:
MessageManager();