3D Repo Bouncer  1.4
All Classes Namespaces Functions Variables Enumerations
repo_listener_stdout.h
1 
23 #pragma once
24 
25 #include "repo_listener_abstract.h"
26 #include <algorithm>
27 #include <iostream>
28 #include <ctime>
29 
30 namespace repo{
31  namespace lib{
33  {
34  public:
35  LogToStdout() {}
36  ~LogToStdout(){};
37 
38  virtual void messageGenerated(const std::string &message)
39  {
40  size_t firstPos = message.find_first_of('%') + 1;
41  size_t secPos = message.find_first_of('%', firstPos + 1);
42  std::string severity = message.substr(firstPos, secPos - firstPos);
43  std::transform(severity.begin(), severity.end(), severity.begin(), ::toupper);
44  const std::string actualMessage = message.substr(secPos + 1);
45 
46  std::cout << "[" << getTimeAsString() << "][" << severity << "]: " << actualMessage;
47  };
48 
49  private:
50 
51  static std::string getTimeAsString()
52  {
53  time_t rawtime;
54  struct tm * timeinfo;
55  char buffer[80];
56 
57  time(&rawtime);
58  timeinfo = localtime(&rawtime);
59 
60  strftime(buffer, 80, "%d-%m-%Y %I:%M:%S", timeinfo);
61  return std::string(buffer);
62  }
63  };
64  }
65 }
Definition: repo_connection_pool_mongo.h:32
Definition: repo_listener_abstract.h:30
Definition: repo_listener_stdout.h:32