OpenShot Library | libopenshot  0.2.6
ZmqLogger.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for ZeroMQ-based Logger class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #ifndef OPENSHOT_LOGGER_H
32 #define OPENSHOT_LOGGER_H
33 
34 
35 #include <iostream>
36 #include <iomanip>
37 #include <fstream>
38 #include <cstdlib>
39 #include <string>
40 #include <sstream>
41 #include <cstdio>
42 #include <ctime>
43 #include <zmq.hpp>
44 #include <unistd.h>
45 #include <OpenShotAudio.h>
46 #include "Settings.h"
47 
48 
49 namespace openshot {
50 
51  /**
52  * @brief This class is used for logging and sending those logs over a ZemoMQ socket to a listener
53  *
54  * OpenShot desktop editor listens to this port, to receive libopenshot debug output. It both logs to
55  * a file and sends the stdout over a socket.
56  */
57  class ZmqLogger {
58  private:
59  juce::CriticalSection loggerCriticalSection;
60  std::string connection;
61 
62  // Logfile related vars
63  std::string file_path;
64  std::ofstream log_file;
65  bool enabled;
66 
67  /// ZMQ Context
68  zmq::context_t *context;
69 
70  /// ZMQ Socket
71  zmq::socket_t *publisher;
72 
73  /// Default constructor
74  ZmqLogger(){}; // Don't allow user to create an instance of this singleton
75 
76 #if __GNUC__ >=7
77  /// Default copy method
78  ZmqLogger(ZmqLogger const&) = delete; // Don't allow the user to assign this instance
79 
80  /// Default assignment operator
81  ZmqLogger & operator=(ZmqLogger const&) = delete; // Don't allow the user to assign this instance
82 #else
83  /// Default copy method
84  ZmqLogger(ZmqLogger const&) {}; // Don't allow the user to assign this instance
85 
86  /// Default assignment operator
87  ZmqLogger & operator=(ZmqLogger const&); // Don't allow the user to assign this instance
88 #endif
89 
90  /// Private variable to keep track of singleton instance
91  static ZmqLogger * m_pInstance;
92 
93  public:
94  /// Create or get an instance of this logger singleton (invoke the class with this method)
95  static ZmqLogger * Instance();
96 
97  /// Append debug information
98  void AppendDebugMethod(
99  std::string method_name,
100  std::string arg1_name="", float arg1_value=-1.0,
101  std::string arg2_name="", float arg2_value=-1.0,
102  std::string arg3_name="", float arg3_value=-1.0,
103  std::string arg4_name="", float arg4_value=-1.0,
104  std::string arg5_name="", float arg5_value=-1.0,
105  std::string arg6_name="", float arg6_value=-1.0
106  );
107 
108  /// Close logger (sockets and/or files)
109  void Close();
110 
111  /// Set or change connection info for logger (i.e. tcp://*:5556)
112  void Connection(std::string new_connection);
113 
114  /// Enable/Disable logging
115  void Enable(bool is_enabled) { enabled = is_enabled;};
116 
117  /// Set or change the file path (optional)
118  void Path(std::string new_path);
119 
120  /// Log message to all subscribers of this logger (if any)
121  void Log(std::string message);
122 
123  /// Log message to a file (if path set)
124  void LogToFile(std::string message);
125  };
126 
127 }
128 
129 #endif
void Log(std::string message)
Log message to all subscribers of this logger (if any)
Definition: ZmqLogger.cpp:120
void LogToFile(std::string message)
Log message to a file (if path set)
Definition: ZmqLogger.cpp:145
void Enable(bool is_enabled)
Enable/Disable logging.
Definition: ZmqLogger.h:115
void Path(std::string new_path)
Set or change the file path (optional)
Definition: ZmqLogger.cpp:152
void Connection(std::string new_connection)
Set or change connection info for logger (i.e. tcp://*:5556)
Definition: ZmqLogger.cpp:80
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:190
void Close()
Close logger (sockets and/or files)
Definition: ZmqLogger.cpp:172
Header file for global Settings class.
This class is used for logging and sending those logs over a ZemoMQ socket to a listener.
Definition: ZmqLogger.h:57
static ZmqLogger * Instance()
Create or get an instance of this logger singleton (invoke the class with this method) ...
Definition: ZmqLogger.cpp:52
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:46