From b4e0ad1ef24fd49bcd5cdd1b6f1dd69768036e07 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 19:03:17 +0100 Subject: move logger's report text creation to lib/Utils/make_descr.cpp Signed-off-by: Denys Vlasenko --- lib/Plugins/Logger.cpp | 79 ++++++------------------------------------------ lib/Utils/Plugin.h | 1 + lib/Utils/make_descr.cpp | 65 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 69 deletions(-) (limited to 'lib') diff --git a/lib/Plugins/Logger.cpp b/lib/Plugins/Logger.cpp index ff7bbb8f..69453d40 100644 --- a/lib/Plugins/Logger.cpp +++ b/lib/Plugins/Logger.cpp @@ -57,85 +57,26 @@ std::string CLogger::Report(const map_crash_report_t& pCrashReport, const std::s { update_client(_("Creating a report...")); - std::stringstream binaryFiles, commonFiles, bigTextFiles, additionalFiles, UUIDFile; - std::ofstream fOut; - - map_crash_report_t::const_iterator it; - for (it = pCrashReport.begin(); it != pCrashReport.end(); it++) - { - if (it->second[CD_TYPE] == CD_TXT) - { - if (it->first != CD_UUID && - it->first != FILENAME_ARCHITECTURE && - it->first != FILENAME_KERNEL && - it->first != FILENAME_PACKAGE) - { - additionalFiles << it->first << std::endl; - additionalFiles << "-----" << std::endl; - additionalFiles << it->second[CD_CONTENT] << std::endl << std::endl; - } - else if (it->first == CD_UUID) - { - UUIDFile << it->first << std::endl; - UUIDFile << "-----" << std::endl; - UUIDFile << it->second[CD_CONTENT] << std::endl << std::endl; - } - else - { - commonFiles << it->first << std::endl; - commonFiles << "-----" << std::endl; - commonFiles << it->second[CD_CONTENT] << std::endl << std::endl; - } - } - if (it->second[CD_TYPE] == CD_ATT) - { - bigTextFiles << it->first << std::endl; - bigTextFiles << "-----" << std::endl; - bigTextFiles << it->second[CD_CONTENT] << std::endl << std::endl; - } - if (it->second[CD_TYPE] == CD_BIN) - { - binaryFiles << it->first << std::endl; - binaryFiles << "-----" << std::endl; - binaryFiles << it->second[CD_CONTENT] << std::endl << std::endl; - } - } - + std::string description = make_description_logger(pCrashReport); + FILE *fOut; if (m_bAppendLogs) { - fOut.open(m_sLogPath.c_str(), std::ios::app); + fOut = fopen(m_sLogPath.c_str(), "a"); } else { - fOut.open(m_sLogPath.c_str()); + fOut = fopen(m_sLogPath.c_str(), "w"); } - if (fOut.is_open()) - { - fOut << "Duplicity check" << std::endl; - fOut << "======" << std::endl << std::endl; - fOut << UUIDFile.str() << std::endl; - fOut << "Common information" << std::endl; - fOut << "======" << std::endl << std::endl; - fOut << commonFiles.str() << std::endl; - fOut << "Additional information" << std::endl; - fOut << "======" << std::endl << std::endl; - fOut << additionalFiles.str() << std::endl; - fOut << "Big Text Files" << std::endl; - fOut << "======" << std::endl; - fOut << bigTextFiles.str() << std::endl; - fOut << "Binary files" << std::endl; - fOut << "======" << std::endl; - fOut << binaryFiles.str() << std::endl; - fOut << std::endl; - fOut.close(); - } - else + if (fOut) { - throw CABRTException(EXCEP_PLUGIN, "CLogger::Report(): Cannot open file: " + m_sLogPath); + fputs(description.c_str(), fOut); + fclose(fOut); + return "file://" + m_sLogPath; } - return "file://" + m_sLogPath; + + throw CABRTException(EXCEP_PLUGIN, "CLogger::Report(): Cannot open file: " + m_sLogPath); } PLUGIN_INFO(REPORTER, diff --git a/lib/Utils/Plugin.h b/lib/Utils/Plugin.h index eabfa10d..00c7e5be 100644 --- a/lib/Utils/Plugin.h +++ b/lib/Utils/Plugin.h @@ -116,5 +116,6 @@ typedef struct SPluginInfo /* helper finctions */ std::string make_description_bz(const map_crash_report_t& pCrashReport); +std::string make_description_logger(const map_crash_report_t& pCrashReport); #endif diff --git a/lib/Utils/make_descr.cpp b/lib/Utils/make_descr.cpp index 8f1c8617..2823dbb4 100644 --- a/lib/Utils/make_descr.cpp +++ b/lib/Utils/make_descr.cpp @@ -85,3 +85,68 @@ string make_description_bz(const map_crash_report_t& pCrashReport) return description; } + +string make_description_logger(const map_crash_report_t& pCrashReport) +{ +// string description; + stringstream binaryFiles, commonFiles, bigTextFiles, additionalFiles, UUIDFile; + + map_crash_report_t::const_iterator it = pCrashReport.begin(); + for (; it != pCrashReport.end(); it++) + { + if (it->second[CD_TYPE] == CD_TXT) + { + if (it->first != CD_UUID + && it->first != FILENAME_ARCHITECTURE + && it->first != FILENAME_KERNEL + && it->first != FILENAME_PACKAGE + ) { + additionalFiles << it->first << std::endl; + additionalFiles << "-----" << std::endl; + additionalFiles << it->second[CD_CONTENT] << std::endl << std::endl; + } + else if (it->first == CD_UUID) + { + UUIDFile << it->first << std::endl; + UUIDFile << "-----" << std::endl; + UUIDFile << it->second[CD_CONTENT] << std::endl << std::endl; + } + else + { + commonFiles << it->first << std::endl; + commonFiles << "-----" << std::endl; + commonFiles << it->second[CD_CONTENT] << std::endl << std::endl; + } + } + if (it->second[CD_TYPE] == CD_ATT) + { + bigTextFiles << it->first << std::endl; + bigTextFiles << "-----" << std::endl; + bigTextFiles << it->second[CD_CONTENT] << std::endl << std::endl; + } + if (it->second[CD_TYPE] == CD_BIN) + { + binaryFiles << it->first << std::endl; + binaryFiles << "-----" << std::endl; + binaryFiles << it->second[CD_CONTENT] << std::endl << std::endl; + } + } + + string description = "Duplicity check\n======\n\n"; + description += UUIDFile.str(); + description += '\n'; + description += "Common information\n======\n\n"; + description += commonFiles.str(); + description += '\n'; + description += "Additional information\n======\n\n"; + description += additionalFiles.str(); + description += '\n'; + description += "Big Text Files\n======\n\n"; + description += bigTextFiles.str(); + description += '\n'; + description += "Binary files\n======\n"; + description += binaryFiles.str(); + description += "\n\n"; + + return description; +} -- cgit