28 #include "../include/ZmqLogger.h" 45 m_pInstance->context = NULL;
46 m_pInstance->publisher = NULL;
47 m_pInstance->connection =
"";
50 m_pInstance->Connection(
"tcp://*:5556");
53 m_pInstance->enabled =
false;
60 void ZmqLogger::Connection(
string new_connection)
63 const GenericScopedLock<CriticalSection> lock(loggerCriticalSection);
66 if (new_connection == connection)
70 connection = new_connection;
72 if (context == NULL) {
74 context =
new zmq::context_t(1);
77 if (publisher != NULL) {
84 publisher =
new zmq::socket_t(*context, ZMQ_PUB);
88 publisher->bind(connection.c_str());
90 }
catch (zmq::error_t &
e) {
91 cout <<
"ZmqLogger::Connection - Error binding to " << connection <<
". Switching to an available port." << endl;
92 connection =
"tcp://*:*";
93 publisher->bind(connection.c_str());
100 void ZmqLogger::Log(
string message)
107 const GenericScopedLock<CriticalSection> lock(loggerCriticalSection);
110 zmq::message_t reply (message.length());
111 memcpy (reply.data(), message.c_str(), message.length());
112 publisher->send(reply);
115 if (log_file.is_open())
116 log_file << message << std::flush;
120 void ZmqLogger::LogToFile(
string message)
123 if (log_file.is_open())
124 log_file << message << std::flush;
127 void ZmqLogger::Path(
string new_path)
130 file_path = new_path;
133 if (log_file.is_open())
137 log_file.open (file_path.c_str(), ios::out | ios::app);
140 time_t now = time(0);
141 tm* localtm = localtime(&now);
142 log_file <<
"------------------------------------------" << endl;
143 log_file <<
"libopenshot logging: " << asctime(localtm);
144 log_file <<
"------------------------------------------" << endl;
147 void ZmqLogger::Close()
150 if (log_file.is_open())
154 if (publisher != NULL) {
162 void ZmqLogger::AppendDebugMethod(
string method_name,
string arg1_name,
float arg1_value,
163 string arg2_name,
float arg2_value,
164 string arg3_name,
float arg3_value,
165 string arg4_name,
float arg4_value,
166 string arg5_name,
float arg5_value,
167 string arg6_name,
float arg6_value)
175 const GenericScopedLock<CriticalSection> lock(loggerCriticalSection);
177 stringstream message;
178 message << fixed << setprecision(4);
179 message << method_name <<
" (";
182 if (arg1_name.length() > 0)
183 message << arg1_name <<
"=" << arg1_value;
185 if (arg2_name.length() > 0)
186 message <<
", " << arg2_name <<
"=" << arg2_value;
188 if (arg3_name.length() > 0)
189 message <<
", " << arg3_name <<
"=" << arg3_value;
191 if (arg4_name.length() > 0)
192 message <<
", " << arg4_name <<
"=" << arg4_value;
194 if (arg5_name.length() > 0)
195 message <<
", " << arg5_name <<
"=" << arg5_value;
197 if (arg6_name.length() > 0)
198 message <<
", " << arg6_name <<
"=" << arg6_value;
201 message <<
")" << endl;
This abstract class is the base class, used by all readers in libopenshot.
This namespace is the default namespace for all code in the openshot library.