3D Repo Bouncer  1.4
repo_log.h
1 
22 #pragma once
23 
24 #include <string>
25 #include <boost/log/trivial.hpp>
26 
27 #include "repo_broadcaster.h"
28 #include "repo_listener_abstract.h"
29 #include "../repo_bouncer_global.h"
30 
31 //------------------------------------------------------------------------------
32 // Logging macros - to avoid having to write all that everytime to log something
33 
34 //The external libraries need to use these 2 because they don't seem to share the same instance of log
35 #define repoLog(MSG) repo::lib::RepoLog::getInstance().log(repo::lib::RepoLog::RepoLogLevel::INFO, MSG)
36 #define repoLogDebug(MSG) repo::lib::RepoLog::getInstance().log(repo::lib::RepoLog::RepoLogLevel::DEBUG, MSG)
37 #define repoLogError(MSG) repo::lib::RepoLog::getInstance().log(repo::lib::RepoLog::RepoLogLevel::ERR, MSG)
38 
39 //internal classes should all be using this.
40 #define repoTrace BOOST_LOG_TRIVIAL(trace)
41 #define repoDebug BOOST_LOG_TRIVIAL(debug)
42 #define repoInfo BOOST_LOG_TRIVIAL(info)
43 #define repoWarning BOOST_LOG_TRIVIAL(warning)
44 #define repoError BOOST_LOG_TRIVIAL(error)
45 #define repoFatal BOOST_LOG_TRIVIAL(fatal)
46 
47 namespace repo{
48  namespace lib{
49  class REPO_API_EXPORT RepoLog
50  {
51  public:
52 
56  enum class RepoLogLevel { TRACE, DEBUG, INFO, WARNING, ERR, FATAL };
57 
58  ~RepoLog();
59 
60  static RepoLog &getInstance()
61  {
62  static RepoLog log = RepoLog();
63  return log;
64  }
65 
71  void log(
72  const RepoLogLevel &severity,
73  const std::string &msg);
74 
79  void logToFile(const std::string &filePath);
80 
93  void setLoggingLevel(const RepoLogLevel &level);
94 
99  void subscribeBroadcaster(RepoBroadcaster *broadcaster);
100 
105  void subscribeListeners(
106  const std::vector<RepoAbstractListener*> &listeners);
107 
108  private:
109 
110  RepoLog();
111  };
112  }
113 }
Definition: repo_connection_pool_mongo.h:32
RepoLogLevel
Definition: repo_log.h:56
Definition: repo_log.h:49