OpenShot Library | libopenshot  0.2.2
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 abstract class is the base class, used by all readers in libopenshot.
51  *
52  * Readers are types of classes that read video, audio, and image files, and
53  * return openshot::Frame objects. The only requirements for a 'reader', are to
54  * derive from this base class, implement the GetFrame method, and call the InitFileInfo() method.
55  */
56  class ZmqLogger {
57  private:
58  CriticalSection loggerCriticalSection;
59  string connection;
60 
61  // Logfile related vars
62  string file_path;
63  ofstream log_file;
64  bool enabled;
65 
66  /// ZMQ Context
67  zmq::context_t *context;
68 
69  /// ZMQ Socket
70  zmq::socket_t *publisher;
71 
72  /// Default constructor
73  ZmqLogger(){}; // Don't allow user to create an instance of this singleton
74 
75 #if __GNUC__ >=7
76  /// Default copy method
77  ZmqLogger(ZmqLogger const&) = delete; // Don't allow the user to assign this instance
78 
79  /// Default assignment operator
80  ZmqLogger & operator=(ZmqLogger const&) = delete; // Don't allow the user to assign this instance
81 #else
82  /// Default copy method
83  ZmqLogger(ZmqLogger const&) {}; // Don't allow the user to assign this instance
84 
85  /// Default assignment operator
86  ZmqLogger & operator=(ZmqLogger const&); // Don't allow the user to assign this instance
87 #endif
88 
89  /// Private variable to keep track of singleton instance
90  static ZmqLogger * m_pInstance;
91 
92  public:
93  /// Create or get an instance of this logger singleton (invoke the class with this method)
94  static ZmqLogger * Instance();
95 
96  /// Append debug information
97  void AppendDebugMethod(string method_name, string arg1_name, float arg1_value,
98  string arg2_name, float arg2_value,
99  string arg3_name, float arg3_value,
100  string arg4_name, float arg4_value,
101  string arg5_name, float arg5_value,
102  string arg6_name, float arg6_value);
103 
104  /// Close logger (sockets and/or files)
105  void Close();
106 
107  /// Set or change connection info for logger (i.e. tcp://*:5556)
108  void Connection(string new_connection);
109 
110  /// Enable/Disable logging
111  void Enable(bool is_enabled) { enabled = is_enabled;};
112 
113  /// Set or change the file path (optional)
114  void Path(string new_path);
115 
116  /// Log message to all subscribers of this logger (if any)
117  void Log(string message);
118 
119  /// Log message to a file (if path set)
120  void LogToFile(string message);
121  };
122 
123 }
124 
125 #endif
void Enable(bool is_enabled)
Enable/Disable logging.
Definition: ZmqLogger.h:111
This abstract class is the base class, used by all readers in libopenshot.
Definition: ZmqLogger.h:56