OpenShot Library | libopenshot  0.2.5
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 <stdlib.h>
39 #include <string>
40 #include <sstream>
41 #include <stdio.h>
42 #include <time.h>
43 #include <zmq.hpp>
44 #include <unistd.h>
45 #include "JuceHeader.h"
46 
47 
48 namespace openshot {
49 
50  /**
51  * @brief This class is used for logging and sending those logs over a ZemoMQ socket to a listener
52  *
53  * OpenShot desktop editor listens to this port, to receive libopenshot debug output. It both logs to
54  * a file and sends the stdout over a socket.
55  */
56  class ZmqLogger {
57  private:
58  juce::CriticalSection loggerCriticalSection;
59  std::string connection;
60 
61  // Logfile related vars
62  std::string file_path;
63  std::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(std::string method_name,
98  std::string arg1_name="", float arg1_value=-1.0,
99  std::string arg2_name="", float arg2_value=-1.0,
100  std::string arg3_name="", float arg3_value=-1.0,
101  std::string arg4_name="", float arg4_value=-1.0,
102  std::string arg5_name="", float arg5_value=-1.0,
103  std::string arg6_name="", float arg6_value=-1.0);
104 
105  /// Close logger (sockets and/or files)
106  void Close();
107 
108  /// Set or change connection info for logger (i.e. tcp://*:5556)
109  void Connection(std::string new_connection);
110 
111  /// Enable/Disable logging
112  void Enable(bool is_enabled) { enabled = is_enabled;};
113 
114  /// Set or change the file path (optional)
115  void Path(std::string new_path);
116 
117  /// Log message to all subscribers of this logger (if any)
118  void Log(std::string message);
119 
120  /// Log message to a file (if path set)
121  void LogToFile(std::string message);
122  };
123 
124 }
125 
126 #endif
openshot::ZmqLogger::Connection
void Connection(std::string new_connection)
Set or change connection info for logger (i.e. tcp://*:5556)
Definition: ZmqLogger.cpp:74
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AudioBufferSource.h:39
openshot::ZmqLogger::Log
void Log(std::string message)
Log message to all subscribers of this logger (if any)
Definition: ZmqLogger.cpp:114
openshot::ZmqLogger::Path
void Path(std::string new_path)
Set or change the file path (optional)
Definition: ZmqLogger.cpp:141
openshot::ZmqLogger::Close
void Close()
Close logger (sockets and/or files)
Definition: ZmqLogger.cpp:161
openshot::ZmqLogger
This class is used for logging and sending those logs over a ZemoMQ socket to a listener.
Definition: ZmqLogger.h:56
openshot::ZmqLogger::Enable
void Enable(bool is_enabled)
Enable/Disable logging.
Definition: ZmqLogger.h:112
openshot::ZmqLogger::Instance
static ZmqLogger * Instance()
Create or get an instance of this logger singleton (invoke the class with this method)
Definition: ZmqLogger.cpp:45
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:179
openshot::ZmqLogger::LogToFile
void LogToFile(std::string message)
Log message to a file (if path set)
Definition: ZmqLogger.cpp:134