Skip to content

Commit

Permalink
Merge pull request #1424 from janosimas/fix_status
Browse files Browse the repository at this point in the history
Fix status
  • Loading branch information
janosimas authored Dec 20, 2017
2 parents 4975555 + ce1604c commit a7cdd2b
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 129 deletions.
2 changes: 1 addition & 1 deletion src/examples/alert/AlertLoggerMock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AlertLoggerMock : public terrama2::services::alert::core::AlertLogger

void log(MessageType messageType, const std::string &description, RegisterId /*registerId*/) const override
{
std::cout << "Message Type: " << messageType << " Message: " << description << std::endl;
std::cout << "Message Type: " << static_cast<int>(messageType) << " Message: " << description << std::endl;
}

};
Expand Down
10 changes: 5 additions & 5 deletions src/examples/core/ProcessLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ int main(int argc, char* argv[])
log.logValue("tag2", "value4", registerID);

// Log errors
log.log(Logger::ERROR_MESSAGE, "Unit Test Error", registerID);
log.log(Logger::ERROR_MESSAGE, "Unit Test second Error", registerID);
log.log(Logger::MessageType::ERROR_MESSAGE, "Unit Test Error", registerID);
log.log(Logger::MessageType::ERROR_MESSAGE, "Unit Test second Error", registerID);

// Log informations
log.log(Logger::INFO_MESSAGE, "Unit Test Info", registerID);
log.log(Logger::INFO_MESSAGE, "Unit Test seconde Info", registerID);
log.log(Logger::MessageType::INFO_MESSAGE, "Unit Test Info", registerID);
log.log(Logger::MessageType::INFO_MESSAGE, "Unit Test seconde Info", registerID);

// Log the end of process with the timestamp of processed data
std::shared_ptr< te::dt::TimeInstantTZ > data_dateTime = terrama2::core::TimeUtils::nowUTC();
log.result(Logger::DONE, data_dateTime, registerID);
log.result(Logger::Status::DONE, data_dateTime, registerID);

// Get the process ID consulting by register ID
ProcessId process_id = log.processID(registerID);
Expand Down
2 changes: 1 addition & 1 deletion src/examples/view/ViewLoggerMock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ViewLoggerMock : public terrama2::services::view::core::ViewLogger

void log(MessageType messageType, const std::string &description, RegisterId) const override
{
std::cout << "Message Type: " << messageType << " Message: " << description << std::endl;
std::cout << "Message Type: " << static_cast<int>(messageType) << " Message: " << description << std::endl;
}

};
Expand Down
4 changes: 2 additions & 2 deletions src/terrama2/core/utility/ProcessLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace terrama2
\brief Possible status of manipulate data.
*/
enum Status
enum class Status
{
ERROR = 1, /*!< Error during process */
START = 2, /*!< The process started */
Expand All @@ -75,7 +75,7 @@ namespace terrama2
\brief Possible status of logged messages.
*/
enum MessageType
enum class MessageType
{
ERROR_MESSAGE = 1,
INFO_MESSAGE = 2,
Expand Down
42 changes: 21 additions & 21 deletions src/terrama2/services/alert/core/AlertExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex
auto dataMap = dataAccessor->getSeries(filter, remover);
if(dataMap.empty())
{
logger->result(AlertLogger::DONE, nullptr, executionPackage.registerId);
logger->log(AlertLogger::WARNING_MESSAGE, QObject::tr("No data to available.").toStdString(), executionPackage.registerId);
logger->result(AlertLogger::Status::DONE, nullptr, executionPackage.registerId);
logger->log(AlertLogger::MessageType::WARNING_MESSAGE, QObject::tr("No data to available.").toStdString(), executionPackage.registerId);
TERRAMA2_LOG_WARNING() << QObject::tr("No data to available.");
emit alertFinished(alertId, executionPackage.executionDate, false);
return;
Expand Down Expand Up @@ -592,7 +592,7 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex
if(datetimeColumnName.empty())
{
QString errMsg = QObject::tr("Unable to identify timestamp column.");
logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
TERRAMA2_LOG_ERROR() << errMsg;
return;
}
Expand All @@ -607,7 +607,7 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex
if(dataSetType->getNumberOfForeignKeys() != 1)
{
QString errMsg = QObject::tr("Invalid number of identifier attribute.");
logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
TERRAMA2_LOG_ERROR() << errMsg;
return;
}
Expand All @@ -617,8 +617,8 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex
if(!idProperty)
{
QString errMsg = QObject::tr("Invalid identifier attribute.");
logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
TERRAMA2_LOG_ERROR() << errMsg;
return;
}
Expand Down Expand Up @@ -681,7 +681,7 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex
if(alertDataSet->isEmpty())
{
QString errMsg = QObject::tr("No alert data for %1 data series.").arg(dataset->dataSeriesId);
logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
TERRAMA2_LOG_ERROR() << errMsg;
return;
}
Expand Down Expand Up @@ -721,8 +721,8 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex
if(!alertGenerated)
{
QString errMsg = QObject::tr("No alert was generated.");
logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId);
TERRAMA2_LOG_WARNING() << errMsg.toStdString();
emit alertFinished(alertId, executionPackage.executionDate, false);
return;
Expand All @@ -733,7 +733,7 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex
logger->setStartProcessingTime(processingStartTime, executionPackage.registerId);
logger->setEndProcessingTime(processingEndTime, executionPackage.registerId);

logger->result(AlertLogger::DONE, executionPackage.executionDate, executionPackage.registerId);
logger->result(AlertLogger::Status::DONE, executionPackage.executionDate, executionPackage.registerId);

TERRAMA2_LOG_INFO() << QObject::tr("Alert '%1' generated successfully").arg(alertPtr->name.c_str());

Expand All @@ -744,34 +744,34 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex
}
catch(const terrama2::Exception& e)
{
logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::ERROR_MESSAGE, boost::get_error_info<terrama2::ErrorDescription>(e)->toStdString(), executionPackage.registerId);
logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, boost::get_error_info<terrama2::ErrorDescription>(e)->toStdString(), executionPackage.registerId);
TERRAMA2_LOG_DEBUG() << boost::get_error_info<terrama2::ErrorDescription>(e)->toStdString();

emit alertFinished(alertId, executionPackage.executionDate, false);
}
catch(const boost::exception& e)
{
logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::ERROR_MESSAGE, boost::diagnostic_information(e), executionPackage.registerId);
logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, boost::diagnostic_information(e), executionPackage.registerId);
TERRAMA2_LOG_ERROR() << boost::diagnostic_information(e);

emit alertFinished(alertId, executionPackage.executionDate, false);
}
catch(const std::exception& e)
{
QString errMsg(e.what());
logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::ERROR_MESSAGE, e.what(), executionPackage.registerId);
logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, e.what(), executionPackage.registerId);
TERRAMA2_LOG_ERROR() << errMsg;

emit alertFinished(alertId, executionPackage.executionDate, false);
}
catch(...)
{
QString errMsg = QObject::tr("Unknown exception");
logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
TERRAMA2_LOG_ERROR() << errMsg;

emit alertFinished(alertId, executionPackage.executionDate, false);
Expand Down Expand Up @@ -869,7 +869,7 @@ te::core::URI terrama2::services::alert::core::AlertExecutor::makeDocument(Repor
errMsg.append(msg);
}

logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
TERRAMA2_LOG_ERROR() << errMsg;
}

Expand All @@ -888,7 +888,7 @@ void terrama2::services::alert::core::AlertExecutor::sendNotification(const std:
if(serverMap.empty())
{
QString errMsg("No message server configured");
logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
TERRAMA2_LOG_ERROR() << errMsg;
}
else
Expand All @@ -907,7 +907,7 @@ void terrama2::services::alert::core::AlertExecutor::sendNotification(const std:
errMsg.append(msg);
}

logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId);
TERRAMA2_LOG_ERROR() << errMsg;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/terrama2/services/alert/core/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void terrama2::services::alert::core::Service::addToQueue(AlertId alertId, std::
else
{
waitQueue_[alertId].push(executionPackage);
logger_->result(AlertLogger::ON_QUEUE, nullptr, executionPackage.registerId);
logger_->result(AlertLogger::Status::ON_QUEUE, nullptr, executionPackage.registerId);
TERRAMA2_LOG_INFO() << tr("Alert %1 added to wait queue.").arg(alertId);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/terrama2/services/analysis/core/AnalysisExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void terrama2::services::analysis::core::AnalysisExecutor::runAnalysis(DataManag
{
for(const std::string& message : messages)
{
logger->log(AnalysisLogger::WARNING_MESSAGE, message, logId);
logger->log(AnalysisLogger::MessageType::WARNING_MESSAGE, message, logId);
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ void terrama2::services::analysis::core::AnalysisExecutor::runAnalysis(DataManag
{
for (const auto& warning: warnings)
{
logger->log(AnalysisLogger::WARNING_MESSAGE, warning, logId);
logger->log(AnalysisLogger::MessageType::WARNING_MESSAGE, warning, logId);
}
}

Expand All @@ -168,13 +168,13 @@ void terrama2::services::analysis::core::AnalysisExecutor::runAnalysis(DataManag
for(const auto& error : errors)
{
errorStr += error + "\n";
logger->log(AnalysisLogger::ERROR_MESSAGE, error, logId);
logger->log(AnalysisLogger::MessageType::ERROR_MESSAGE, error, logId);
}

QString errMsg = QObject::tr("Analysis %1 (%2) finished with the following error(s):\n%3").arg(analysis->id).arg(QString::fromStdString(startTime->toString()), QString::fromStdString(errorStr));
TERRAMA2_LOG_INFO() << errMsg;

logger->result(AnalysisLogger::ERROR, startTime, logId);
logger->result(AnalysisLogger::Status::ERROR, startTime, logId);

emit analysisFinished(analysis->id, startTime, false);
}
Expand All @@ -188,7 +188,7 @@ void terrama2::services::analysis::core::AnalysisExecutor::runAnalysis(DataManag
logger->setStartProcessingTime(processingStartTime, executionPackage.registerId);
logger->setEndProcessingTime(processingEndTime, executionPackage.registerId);

logger->result(AnalysisLogger::DONE, startTime, logId);
logger->result(AnalysisLogger::Status::DONE, startTime, logId);

QString errMsg = QObject::tr("Analysis %1 finished successfully: %2").arg(analysis->id).arg(startTime->toString().c_str());
TERRAMA2_LOG_INFO() << errMsg;
Expand Down
2 changes: 1 addition & 1 deletion src/terrama2/services/analysis/core/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void terrama2::services::analysis::core::Service::addToQueue(AnalysisId analysis
else
{
waitQueue_[analysisId].push(executionPackage);
logger_->result(AnalysisLogger::ON_QUEUE, nullptr, executionPackage.registerId);
logger_->result(AnalysisLogger::Status::ON_QUEUE, nullptr, executionPackage.registerId);
TERRAMA2_LOG_INFO() << tr("Analysis %1 added to wait queue.").arg(analysisId);
}
}
Expand Down
Loading

0 comments on commit a7cdd2b

Please sign in to comment.