logic: write output of Python indexer processes to log file
This commit is contained in:
@@ -219,37 +219,32 @@ void TaskExecuteCustomCommands::runIndexerCommand(std::shared_ptr<IndexerCommand
|
||||
|
||||
m_storage->beforeErrorRecording();
|
||||
|
||||
std::wstring processOutput;
|
||||
std::wstring errorMessage;
|
||||
const int result = utility::executeProcessAndGetExitCode(command, {}, m_projectDirectory, -1, &processOutput, &errorMessage);
|
||||
const int result = utility::executeProcessAndGetExitCode(command, {}, m_projectDirectory, -1, true, &errorMessage);
|
||||
|
||||
m_storage->afterErrorRecording();
|
||||
|
||||
if (errorMessage.size() > 0 || processOutput.size() > 3 || result != 0)
|
||||
if (result == 0 && errorMessage.empty())
|
||||
{
|
||||
if (result == 0 && errorMessage.empty())
|
||||
std::wstring message = L"Process returned successfully.\n";
|
||||
LOG_INFO(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring statusText = L"command \"" + indexerCommand->getCustomCommand() + L"\" returned";
|
||||
if (result != 0)
|
||||
{
|
||||
std::wstring message = L"Process returned successfully";
|
||||
if (processOutput.empty())
|
||||
{
|
||||
message += L".";
|
||||
}
|
||||
else
|
||||
{
|
||||
message += L" with message \"" + processOutput + L"\".";
|
||||
}
|
||||
message += L"\n";
|
||||
LOG_INFO(message);
|
||||
statusText += L" code \"" + std::to_wstring(result) + L"\"";
|
||||
}
|
||||
else
|
||||
if (!errorMessage.empty())
|
||||
{
|
||||
LOG_ERROR_STREAM(<< "process returned \"" << result << "\" with message:\n" << utility::encodeToUtf8(processOutput));
|
||||
MessageShowStatus().dispatch();
|
||||
MessageStatus(
|
||||
L"command \"" + indexerCommand->getCustomCommand() + L"\" returned code \"" + std::to_wstring(result) + L"\"" +
|
||||
L" with message \"" + errorMessage + L"\"" +
|
||||
L" and output \"" + processOutput + L"\".", true, false, true).dispatch();
|
||||
statusText += L" with message \"" + errorMessage + L"\"";
|
||||
}
|
||||
statusText += L".";
|
||||
|
||||
LOG_ERROR(statusText);
|
||||
MessageShowStatus().dispatch();
|
||||
MessageStatus(statusText, true, false, true).dispatch();
|
||||
}
|
||||
|
||||
indexedSourceFileCount++;
|
||||
|
||||
@@ -13,6 +13,39 @@
|
||||
#include "UserPaths.h"
|
||||
#include "utilityString.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
void logProcessStreams(QProcess& process, std::wstring& outputBuffer, std::wstring& errorBuffer)
|
||||
{
|
||||
{
|
||||
outputBuffer += QString(process.readAllStandardOutput()).toStdWString();
|
||||
std::vector<std::wstring> outputLines = utility::split<std::vector<std::wstring>>(outputBuffer, L"\n");
|
||||
for (size_t i = 0; i < outputLines.size() - 1; i++)
|
||||
{
|
||||
if (outputLines[i].back() == L'\r')
|
||||
{
|
||||
outputLines[i].pop_back();
|
||||
}
|
||||
LOG_INFO_BARE(L"Process output: " + outputLines[i]);
|
||||
}
|
||||
outputBuffer = outputLines.back();
|
||||
}
|
||||
{
|
||||
errorBuffer += QString(process.readAllStandardError()).toStdWString();
|
||||
std::vector<std::wstring> errorLines = utility::split<std::vector<std::wstring>>(errorBuffer, L"\n");
|
||||
for (size_t i = 0; i < errorLines.size() - 1; i++)
|
||||
{
|
||||
if (errorLines[i].back() == L'\r')
|
||||
{
|
||||
errorLines[i].pop_back();
|
||||
}
|
||||
LOG_ERROR_BARE(L"Process error: " + errorLines[i]);
|
||||
}
|
||||
errorBuffer = errorLines.back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace utility
|
||||
{
|
||||
std::mutex s_runningProcessesMutex;
|
||||
@@ -108,7 +141,7 @@ int utility::executeProcessAndGetExitCode(
|
||||
const std::vector<std::wstring>& commandArguments,
|
||||
const FilePath& workingDirectory,
|
||||
const int timeout,
|
||||
std::wstring* processOutput,
|
||||
bool logProcessOutput,
|
||||
std::wstring* errorMessage
|
||||
){
|
||||
QProcess process;
|
||||
@@ -163,28 +196,36 @@ int utility::executeProcessAndGetExitCode(
|
||||
s_runningProcesses.insert(&process);
|
||||
}
|
||||
|
||||
process.waitForFinished(timeout);
|
||||
{
|
||||
std::wstring outputBuffer;
|
||||
std::wstring errorBuffer;
|
||||
if (timeout == -1)
|
||||
{
|
||||
while (!process.waitForFinished(1000))
|
||||
{
|
||||
if (logProcessOutput)
|
||||
{
|
||||
logProcessStreams(process, outputBuffer, errorBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
process.waitForFinished(timeout);
|
||||
}
|
||||
|
||||
if (logProcessOutput)
|
||||
{
|
||||
logProcessStreams(process, outputBuffer, errorBuffer);
|
||||
}
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_runningProcessesMutex);
|
||||
s_runningProcesses.erase(&process);
|
||||
}
|
||||
|
||||
int exitCode = process.exitCode();
|
||||
|
||||
if (processOutput != nullptr)
|
||||
{
|
||||
if (exitCode != 0)
|
||||
{
|
||||
*processOutput = utility::trim(QString(process.readAllStandardError()).toStdWString());
|
||||
}
|
||||
else
|
||||
{
|
||||
*processOutput = utility::trim(QString(process.readAll()).toStdWString());
|
||||
}
|
||||
}
|
||||
|
||||
const int exitCode = process.exitCode();
|
||||
process.close();
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace utility
|
||||
const std::vector<std::wstring>& commandArguments,
|
||||
const FilePath& workingDirectory = FilePath(),
|
||||
const int timeout = 30000,
|
||||
std::wstring* processOutput = nullptr,
|
||||
bool logProcessOutput = false,
|
||||
std::wstring* errorMessage = nullptr
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user