hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DRCEPrintStatus.cpp
Go to the documentation of this file.
1 #include <iomanip>
2 #include <sstream>
3 
4 #include <Poco/ConsoleChannel.h>
5 #include <Poco/FileChannel.h>
6 #include <Poco/FormattingChannel.h>
7 #include <Poco/PatternFormatter.h>
8 #include <Poco/Logger.h>
9 #include <Poco/AutoPtr.h>
10 
11 #include "DRCEPrintStatus.hpp"
12 
13 namespace HCE
14 {
15 namespace drce
16 {
17 namespace tests
18 {
19 //-----------------------------------------------------------------------------
20 DRCEPrintStatus::DRCEPrintStatus(const std::string& debugLevel_, const std::string& postfix_)
21 : debugLevel(debugLevel_), postfix(postfix_)
22 {
23  Poco::AutoPtr<Poco::ConsoleChannel> pCons(new Poco::ConsoleChannel());
24  pCons->open();
25 
26  Poco::Logger::get(debugLevel).setChannel(pCons);
27  Poco::Logger::get(debugLevel).setLevel(debugLevel);
28 }
29 //-----------------------------------------------------------------------------
30 void DRCEPrintStatus::operator ()(const std::string& msg, unsigned int width)
31 {
32  std::stringstream outMsg, fmtMsg;
33  outMsg << std::setw(width) << msg;
34 
35  if (!postfix.empty())
36  outMsg << postfix;
37 
38  fmtMsg << std::string(outMsg.str().length()+1,'=') << "\n" << outMsg.str() << "\n" << std::string(outMsg.str().length()+1,'=');
39  int level = Poco::Logger::get(debugLevel).getLevel();
40  Poco::Logger::get(debugLevel).log(Poco::Message("", fmtMsg.str(), static_cast<Poco::Message::Priority>(level)));
41 }
42 //-----------------------------------------------------------------------------
44 {
45  std::ostringstream outMsg;
46  outMsg << "ErrorMsg: " << rhs.getErrorMsg() << "\tErrorCode: " << rhs.getErrorCode() << std::endl;
47  return outMsg.str();
48 }
49 //-----------------------------------------------------------------------------
51 {
52  std::ostringstream outMsg;
53  outMsg << "ErrorMsg: " << rhs.getErrorMsg() << "\tErrorCode: " << rhs.getErrorCode() << std::endl;
54  return outMsg.str();
55 }
56 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
58 } // namespace tests
59 } // namespace drce
60 } // namespace HCE