31 #include "../include/ZmqLogger.h"
52 m_pInstance->context = NULL;
53 m_pInstance->publisher = NULL;
54 m_pInstance->connection =
"";
57 m_pInstance->Connection(
"tcp://*:5556");
60 m_pInstance->enabled =
false;
65 ResvgRenderer::initLog();
74 void ZmqLogger::Connection(
string new_connection)
77 const GenericScopedLock<CriticalSection> lock(loggerCriticalSection);
80 if (new_connection == connection)
84 connection = new_connection;
86 if (context == NULL) {
88 context =
new zmq::context_t(1);
91 if (publisher != NULL) {
98 publisher =
new zmq::socket_t(*context, ZMQ_PUB);
102 publisher->bind(connection.c_str());
104 }
catch (zmq::error_t &e) {
105 cout <<
"ZmqLogger::Connection - Error binding to " << connection <<
". Switching to an available port." << endl;
106 connection =
"tcp://*:*";
107 publisher->bind(connection.c_str());
114 void ZmqLogger::Log(
string message)
121 const GenericScopedLock<CriticalSection> lock(loggerCriticalSection);
124 zmq::message_t reply (message.length());
125 memcpy (reply.data(), message.c_str(), message.length());
126 publisher->send(reply);
129 if (log_file.is_open())
130 log_file << message << std::flush;
134 void ZmqLogger::LogToFile(
string message)
137 if (log_file.is_open())
138 log_file << message << std::flush;
141 void ZmqLogger::Path(
string new_path)
144 file_path = new_path;
147 if (log_file.is_open())
151 log_file.open (file_path.c_str(), ios::out | ios::app);
154 time_t now = time(0);
155 tm* localtm = localtime(&now);
156 log_file <<
"------------------------------------------" << endl;
157 log_file <<
"libopenshot logging: " << asctime(localtm);
158 log_file <<
"------------------------------------------" << endl;
161 void ZmqLogger::Close()
167 if (log_file.is_open())
171 if (publisher != NULL) {
179 void ZmqLogger::AppendDebugMethod(
string method_name,
180 string arg1_name,
float arg1_value,
181 string arg2_name,
float arg2_value,
182 string arg3_name,
float arg3_value,
183 string arg4_name,
float arg4_value,
184 string arg5_name,
float arg5_value,
185 string arg6_name,
float arg6_value)
193 const GenericScopedLock<CriticalSection> lock(loggerCriticalSection);
195 stringstream message;
196 message << fixed << setprecision(4);
197 message << method_name <<
" (";
200 if (arg1_name.length() > 0)
201 message << arg1_name <<
"=" << arg1_value;
203 if (arg2_name.length() > 0)
204 message <<
", " << arg2_name <<
"=" << arg2_value;
206 if (arg3_name.length() > 0)
207 message <<
", " << arg3_name <<
"=" << arg3_value;
209 if (arg4_name.length() > 0)
210 message <<
", " << arg4_name <<
"=" << arg4_value;
212 if (arg5_name.length() > 0)
213 message <<
", " << arg5_name <<
"=" << arg5_value;
215 if (arg6_name.length() > 0)
216 message <<
", " << arg6_name <<
"=" << arg6_value;
219 message <<
")" << endl;