42 m_pInstance->context = NULL;
43 m_pInstance->publisher = NULL;
44 m_pInstance->connection =
"";
50 m_pInstance->enabled =
false;
55 ResvgRenderer::initLog();
66 const std::lock_guard<std::recursive_mutex> lock(loggerMutex);
69 if (new_connection == connection)
73 connection = new_connection;
75 if (context == NULL) {
77 context =
new zmq::context_t(1);
80 if (publisher != NULL) {
87 publisher =
new zmq::socket_t(*context, ZMQ_PUB);
91 publisher->bind(connection.c_str());
93 }
catch (zmq::error_t &e) {
94 std::cout <<
"ZmqLogger::Connection - Error binding to " << connection <<
". Switching to an available port." << std::endl;
95 connection =
"tcp://*:*";
96 publisher->bind(connection.c_str());
100 std::this_thread::sleep_for(std::chrono::milliseconds(250));
110 const std::lock_guard<std::recursive_mutex> lock(loggerMutex);
113 zmq::message_t reply (message.length());
114 std::memcpy (reply.data(), message.c_str(), message.length());
116 #if ZMQ_VERSION > ZMQ_MAKE_VERSION(4, 3, 1) 118 publisher->send(reply, zmq::send_flags::dontwait);
120 publisher->send(reply);
131 if (log_file.is_open())
132 log_file << message << std::flush;
138 file_path = new_path;
141 if (log_file.is_open())
145 log_file.open (file_path.c_str(), std::ios::out | std::ios::app);
148 std::time_t now = std::time(0);
149 std::tm* localtm = std::localtime(&now);
150 log_file <<
"------------------------------------------" << std::endl;
151 log_file <<
"libopenshot logging: " << std::asctime(localtm);
152 log_file <<
"------------------------------------------" << std::endl;
161 if (log_file.is_open())
165 if (publisher != NULL) {
172 if (context != NULL) {
179 std::string arg1_name,
float arg1_value,
180 std::string arg2_name,
float arg2_value,
181 std::string arg3_name,
float arg3_value,
182 std::string arg4_name,
float arg4_value,
183 std::string arg5_name,
float arg5_value,
184 std::string arg6_name,
float arg6_value)
192 const std::lock_guard<std::recursive_mutex> lock(loggerMutex);
194 std::stringstream message;
195 message << std::fixed << std::setprecision(4);
198 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;
218 message <<
")" << std::endl;
222 std::clog << message.str();
void Log(std::string message)
Log message to all subscribers of this logger (if any)
void LogToFile(std::string message)
Log message to a file (if path set)
bool DEBUG_TO_STDERR
Whether to dump ZeroMQ debug messages to stderr.
void Path(std::string new_path)
Set or change the file path (optional)
void Connection(std::string new_connection)
Set or change connection info for logger (i.e. tcp://*:5556)
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.
Header file for all Exception classes.
void Close()
Close logger (sockets and/or files)
Header file for ZeroMQ-based Logger class.
Header file for global Settings class.
This class is used for logging and sending those logs over a ZemoMQ socket to a listener.
static ZmqLogger * Instance()
Create or get an instance of this logger singleton (invoke the class with this method) ...
This namespace is the default namespace for all code in the openshot library.
static Settings * Instance()
Create or get an instance of this logger singleton (invoke the class with this method) ...