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