OpenShot Library | libopenshot  0.3.3
ZmqLogger.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_LOGGER_H
14 #define OPENSHOT_LOGGER_H
15 
16 
17 #include <fstream>
18 #include <memory>
19 #include <mutex>
20 #include <string>
21 
22 #include <zmq.hpp>
23 
24 namespace openshot {
25 
32  class ZmqLogger {
33  private:
34  std::recursive_mutex loggerMutex;
35  std::string connection;
36 
37  // Logfile related vars
38  std::string file_path;
39  std::ofstream log_file;
40  bool enabled;
41 
43  zmq::context_t *context;
44 
46  zmq::socket_t *publisher;
47 
49  ZmqLogger(){}; // Don't allow user to create an instance of this singleton
50 
51 #if __GNUC__ >=7
52  ZmqLogger(ZmqLogger const&) = delete; // Don't allow the user to assign this instance
54 
56  ZmqLogger & operator=(ZmqLogger const&) = delete; // Don't allow the user to assign this instance
57 #else
58  ZmqLogger(ZmqLogger const&) {}; // Don't allow the user to assign this instance
60 
62  ZmqLogger & operator=(ZmqLogger const&); // Don't allow the user to assign this instance
63 #endif
64 
66  static ZmqLogger * m_pInstance;
67 
68  public:
70  static ZmqLogger * Instance();
71 
73  void AppendDebugMethod(
74  std::string method_name,
75  std::string arg1_name="", float arg1_value=-1.0,
76  std::string arg2_name="", float arg2_value=-1.0,
77  std::string arg3_name="", float arg3_value=-1.0,
78  std::string arg4_name="", float arg4_value=-1.0,
79  std::string arg5_name="", float arg5_value=-1.0,
80  std::string arg6_name="", float arg6_value=-1.0
81  );
82 
84  void Close();
85 
87  void Connection(std::string new_connection);
88 
90  void Enable(bool is_enabled) { enabled = is_enabled;};
91 
93  void Path(std::string new_path);
94 
96  void Log(std::string message);
97 
99  void LogToFile(std::string message);
100  };
101 
102 }
103 
104 #endif
openshot::ZmqLogger::Connection
void Connection(std::string new_connection)
Set or change connection info for logger (i.e. tcp://*:5556)
Definition: ZmqLogger.cpp:63
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::ZmqLogger::Log
void Log(std::string message)
Log message to all subscribers of this logger (if any)
Definition: ZmqLogger.cpp:103
openshot::ZmqLogger::Path
void Path(std::string new_path)
Set or change the file path (optional)
Definition: ZmqLogger.cpp:135
openshot::ZmqLogger::Close
void Close()
Close logger (sockets and/or files)
Definition: ZmqLogger.cpp:155
openshot::ZmqLogger
This class is used for logging and sending those logs over a ZemoMQ socket to a listener.
Definition: ZmqLogger.h:32
openshot::ZmqLogger::Enable
void Enable(bool is_enabled)
Enable/Disable logging.
Definition: ZmqLogger.h:90
openshot::ZmqLogger::Instance
static ZmqLogger * Instance()
Create or get an instance of this logger singleton (invoke the class with this method)
Definition: ZmqLogger.cpp:35
openshot::ZmqLogger::AppendDebugMethod
void AppendDebugMethod(std::string method_name, std::string arg1_name="", float arg1_value=-1.0, std::string arg2_name="", float arg2_value=-1.0, std::string arg3_name="", float arg3_value=-1.0, std::string arg4_name="", float arg4_value=-1.0, std::string arg5_name="", float arg5_value=-1.0, std::string arg6_name="", float arg6_value=-1.0)
Append debug information.
Definition: ZmqLogger.cpp:178
openshot::ZmqLogger::LogToFile
void LogToFile(std::string message)
Log message to a file (if path set)
Definition: ZmqLogger.cpp:128