diff options
27 files changed, 132 insertions, 102 deletions
diff --git a/apps/uscxml-browser.cpp b/apps/uscxml-browser.cpp index 99f646f..8ab5524 100644 --- a/apps/uscxml-browser.cpp +++ b/apps/uscxml-browser.cpp @@ -56,7 +56,7 @@ int main(int argc, char** argv) { InterpreterOptions* currOptions = options.interpreters[0].second; std::string documentURL = options.interpreters[0].first; - LOG(USCXML_INFO) << "Processing " << documentURL; + LOGD(USCXML_INFO) << "Processing " << documentURL; try { Interpreter interpreter = Interpreter::fromURL(documentURL); @@ -82,7 +82,7 @@ int main(int argc, char** argv) { interpreters.push_back(interpreter); } else { - LOG(USCXML_ERROR) << "Cannot create interpreter from " << documentURL; + LOGD(USCXML_ERROR) << "Cannot create interpreter from " << documentURL; } } catch (Event e) { std::cout << e << std::endl; diff --git a/apps/uscxml-transform.cpp b/apps/uscxml-transform.cpp index 0cf538c..2b440ff 100644 --- a/apps/uscxml-transform.cpp +++ b/apps/uscxml-transform.cpp @@ -211,7 +211,7 @@ int main(int argc, char** argv) { Interpreter interpreter; try { if (inputFile.size() == 0 || inputFile == "-") { - LOG(USCXML_INFO) << "Reading SCXML from STDIN"; + LOGD(USCXML_INFO) << "Reading SCXML from STDIN"; std::stringstream ss; std::string line; while (std::getline(std::cin, line)) { @@ -254,7 +254,7 @@ int main(int argc, char** argv) { } if (!interpreter) { - LOG(USCXML_ERROR) << "Cannot create interpreter from " << inputFile; + LOGD(USCXML_ERROR) << "Cannot create interpreter from " << inputFile; exit(EXIT_FAILURE); } diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 190240f..1aa07df 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -170,13 +170,13 @@ Interpreter Interpreter::fromURL(const std::string& url) { } catch (const XERCESC_NS::SAXParseException& toCatch) { - LOG(USCXML_ERROR) << X(toCatch.getMessage()); + LOGD(USCXML_ERROR) << X(toCatch.getMessage()); } catch (const XERCESC_NS::RuntimeException& toCatch) { - LOG(USCXML_ERROR) << X(toCatch.getMessage()); + LOGD(USCXML_ERROR) << X(toCatch.getMessage()); } catch (const XERCESC_NS::XMLException& toCatch) { - LOG(USCXML_ERROR) << X(toCatch.getMessage()); + LOGD(USCXML_ERROR) << X(toCatch.getMessage()); } catch (const XERCESC_NS::DOMException& toCatch) { - LOG(USCXML_ERROR) << X(toCatch.getMessage()); + LOGD(USCXML_ERROR) << X(toCatch.getMessage()); } return interpreter; @@ -227,6 +227,10 @@ void Interpreter::removeMonitor(InterpreterMonitor* monitor) { return _impl->removeMonitor(monitor); } +Logger Interpreter::getLogger() { + return _impl->getLogger(); +} + std::list<InterpreterIssue> Interpreter::validate() { return InterpreterIssue::forInterpreter(_impl.get()); } diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index e9e472d..cf87fc4 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -28,6 +28,7 @@ #include <vector> #include "uscxml/interpreter/MicroStep.h" +#include "uscxml/interpreter/Logging.h" #include "uscxml/plugins/DataModel.h" #include "uscxml/plugins/Factory.h" #include "uscxml/interpreter/ContentExecutor.h" @@ -51,6 +52,7 @@ class InterpreterIssue; */ class USCXML_API ActionLanguage { public: + Logger logger; ///< The logger instance to use for messages MicroStep microStepper; ///< The microstepper instance to use DataModel dataModel; ///< The datamodel to use ContentExecutor execContent; ///< To process executable content elements @@ -194,6 +196,10 @@ public: */ void removeMonitor(InterpreterMonitor* monitor); + /** + * Return the logger associated with this interpreter + */ + Logger getLogger(); /** * Return the actual implementation of the Interperter. diff --git a/src/uscxml/debug/DebugSession.cpp b/src/uscxml/debug/DebugSession.cpp index 5b68f8e..fff6fe1 100644 --- a/src/uscxml/debug/DebugSession.cpp +++ b/src/uscxml/debug/DebugSession.cpp @@ -215,7 +215,7 @@ void DebugSession::run(void* instance) { // return; // } } - LOG(USCXML_DEBUG) << "done"; + LOG(INSTANCE->_interpreter.getLogger(), USCXML_DEBUG) << "done"; } Data DebugSession::debugStop(const Data& data) { diff --git a/src/uscxml/debug/DebuggerServlet.cpp b/src/uscxml/debug/DebuggerServlet.cpp index 016d67c..56b43d5 100644 --- a/src/uscxml/debug/DebuggerServlet.cpp +++ b/src/uscxml/debug/DebuggerServlet.cpp @@ -238,6 +238,23 @@ void DebuggerServlet::processListSessions(const HTTPServer::Request& request) { returnData(request, replyData); } +std::shared_ptr<LoggerImpl> DebuggerServlet::create() { + assert(false); + return std::shared_ptr<LoggerImpl>(this); +} + +void DebuggerServlet::log(LogSeverity severity, const Event& event) { + pushData(std::shared_ptr<DebugSession>(), event.data); +} + +void DebuggerServlet::log(LogSeverity severity, const Data& data) { + pushData(std::shared_ptr<DebugSession>(), data); +} + +void DebuggerServlet::log(LogSeverity severity, const std::string& message) { + pushData(std::shared_ptr<DebugSession>(), Data(message)); +} + /* void DebuggerServlet::handle(const el::LogDispatchData* data) { } diff --git a/src/uscxml/debug/DebuggerServlet.h b/src/uscxml/debug/DebuggerServlet.h index 05e1397..8d487b2 100644 --- a/src/uscxml/debug/DebuggerServlet.h +++ b/src/uscxml/debug/DebuggerServlet.h @@ -21,7 +21,7 @@ #define DEBUGGERSERVLET_H_ATUMDA3G #include "uscxml/Common.h" -#include "uscxml/interpreter/Logging.h" +#include "uscxml/interpreter/LoggingImpl.h" #include "uscxml/util/BlockingQueue.h" #include "uscxml/server/HTTPServer.h" @@ -29,27 +29,8 @@ namespace uscxml { -class USCXML_API DebuggerServlet : public Debugger, public HTTPServlet, public Logger { +class USCXML_API DebuggerServlet : public Debugger, public HTTPServlet, public LoggerImpl { public: - class LogMessage : public Data { - public: -#if 0 - LogMessage(google::LogSeverity severity, const char* full_filename, - const char* base_filename, int line, - const struct ::tm* tm_time, - std::string message, std::string formatted) { - - compound["severity"] = severity; - compound["fullFilename"] = Data(full_filename, Data::VERBATIM); - compound["baseFilename"] = Data(base_filename, Data::VERBATIM); - compound["line"] = line; - compound["message"] = Data(message, Data::VERBATIM); - compound["time"] = Data(mktime((struct ::tm*)tm_time), Data::INTERPRETED); - compound["formatted"] = Data(formatted, Data::VERBATIM); - } -#endif - }; - virtual ~DebuggerServlet() {} // from Debugger @@ -85,14 +66,12 @@ public: // void processRemoveBreakPoint(const HTTPServer::Request& request); // void processPoll(const HTTPServer::Request& request); - // Logsink - /** - virtual void send(google::LogSeverity severity, const char* full_filename, - const char* base_filename, int line, - const struct ::tm* tm_time, - const char* message, size_t message_len); - void handle(const el::LogDispatchData* data); - */ + // Logger + virtual std::shared_ptr<LoggerImpl> create(); + + virtual void log(LogSeverity severity, const Event& event); + virtual void log(LogSeverity severity, const Data& data); + virtual void log(LogSeverity severity, const std::string& message); protected: void serverPushData(std::shared_ptr<DebugSession>); diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 376561d..60a45e5 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -144,7 +144,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { } else if (delayAttr.unit.length() == 0) { // unit less delay is interpreted as milliseconds delayMs = strTo<uint32_t>(delayAttr.value); } else { - LOG(USCXML_ERROR) << "Cannot make sense of delay value " << delay << ": does not end in 's' or 'ms'"; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "Cannot make sense of delay value " << delay << ": does not end in 's' or 'ms'"; } } } catch (Event e) { @@ -355,14 +355,14 @@ void BasicContentExecutor::process(XERCESC_NS::DOMElement* block, const X& xmlPr } else if (iequals(tagName, xmlPrefix.str() + "script")) { processScript(block); } else { - LOG(USCXML_ERROR) << tagName; + LOG(_callbacks->getLogger(), USCXML_ERROR) << tagName; assert(false); } } catch (ErrorEvent exc) { Event e(exc); _callbacks->enqueueInternal(e); - LOG(USCXML_ERROR) << exc << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << exc << std::endl; USCXML_MONITOR_CALLBACK1(_callbacks->getMonitors(), afterExecutingContent, block); throw e; // will be catched in microstepper diff --git a/src/uscxml/interpreter/ContentExecutorImpl.h b/src/uscxml/interpreter/ContentExecutorImpl.h index 7eaebbc..dfd4c5f 100644 --- a/src/uscxml/interpreter/ContentExecutorImpl.h +++ b/src/uscxml/interpreter/ContentExecutorImpl.h @@ -24,6 +24,7 @@ #include "uscxml/Common.h" #include "uscxml/messages/Event.h" #include "uscxml/interpreter/InterpreterMonitor.h" +#include "uscxml/interpreter/Logging.h" #include <string> #include <set> @@ -73,6 +74,7 @@ public: /** Monitoring */ virtual std::set<InterpreterMonitor*> getMonitors() = 0; virtual Interpreter getInterpreter() = 0; + virtual Logger getLogger() = 0; }; diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp index 85c77a8..43059bf 100644 --- a/src/uscxml/interpreter/InterpreterImpl.cpp +++ b/src/uscxml/interpreter/InterpreterImpl.cpp @@ -249,7 +249,7 @@ bool InterpreterImpl::isTrue(const std::string& expr) { } catch (ErrorEvent e) { // test 244: deliver error execution - LOG(USCXML_ERROR) << e; + LOG(getLogger(), USCXML_ERROR) << e; // test 344 enqueueInternal(e); diff --git a/src/uscxml/interpreter/InterpreterImpl.h b/src/uscxml/interpreter/InterpreterImpl.h index ade2a91..f4fe93e 100644 --- a/src/uscxml/interpreter/InterpreterImpl.h +++ b/src/uscxml/interpreter/InterpreterImpl.h @@ -225,6 +225,8 @@ public: /** --- */ void setActionLanguage(const ActionLanguage& al) { + if (al.logger) // we intialized _logger as the default logger already + _logger = al.logger; _execContent = al.execContent; _microStepper = al.microStepper; _dataModel = al.dataModel; @@ -237,6 +239,10 @@ public: _factory = factory; } + virtual Logger getLogger() { + return _logger; + } + static std::map<std::string, std::weak_ptr<InterpreterImpl> > getInstances(); virtual XERCESC_NS::DOMDocument* getDocument() { @@ -281,6 +287,7 @@ protected: MicroStep _microStepper; DataModel _dataModel; ContentExecutor _execContent; + Logger _logger = Logger::getDefault(); InterpreterState _state; diff --git a/src/uscxml/interpreter/Logging.h b/src/uscxml/interpreter/Logging.h index dd59e95..7221d5b 100644 --- a/src/uscxml/interpreter/Logging.h +++ b/src/uscxml/interpreter/Logging.h @@ -28,8 +28,10 @@ #include <memory> -#define LOG(lvl) uscxml::Logger::getDefault().log(lvl) -#define LOG2(lvl, thing) uscxml::Logger::getDefault().log(lvl, thing); +#define LOG(logger, lvl) logger.log(lvl) +#define LOG2(logger, lvl, thing) logger.log(lvl, thing) +#define LOGD(lvl) uscxml::Logger::getDefault().log(lvl) +#define LOGD2(lvl, thing) uscxml::Logger::getDefault().log(lvl, thing); namespace uscxml { diff --git a/src/uscxml/interpreter/MicroStepImpl.h b/src/uscxml/interpreter/MicroStepImpl.h index cdb98f2..1544e78 100644 --- a/src/uscxml/interpreter/MicroStepImpl.h +++ b/src/uscxml/interpreter/MicroStepImpl.h @@ -59,6 +59,7 @@ public: /** Monitoring */ virtual std::set<InterpreterMonitor*> getMonitors() = 0; virtual Interpreter getInterpreter() = 0; + virtual Logger getLogger() = 0; }; /** diff --git a/src/uscxml/messages/Data.cpp b/src/uscxml/messages/Data.cpp index 5d7dbf2..b2d08e4 100644 --- a/src/uscxml/messages/Data.cpp +++ b/src/uscxml/messages/Data.cpp @@ -101,7 +101,7 @@ Data Data::fromJSON(const std::string& jsonString) { } t = (jsmntok_t*)malloc((nrTokens + 1) * sizeof(jsmntok_t)); if (t == NULL) { - LOG(USCXML_ERROR) << "Cannot parse JSON, ran out of memory!"; + throw ErrorEvent("Cannot parse JSON, ran out of memory!"); return data; } memset(t, 0, (nrTokens + 1) * sizeof(jsmntok_t)); @@ -112,13 +112,13 @@ Data Data::fromJSON(const std::string& jsonString) { if (rv != 0) { switch (rv) { case JSMN_ERROR_NOMEM: - LOG(USCXML_ERROR) << "Cannot parse JSON, not enough tokens were provided!"; + throw ErrorEvent("Cannot parse JSON, not enough tokens were provided!"); break; case JSMN_ERROR_INVAL: - LOG(USCXML_ERROR) << "Cannot parse JSON, invalid character inside JSON string!"; + throw ErrorEvent("Cannot parse JSON, invalid character inside JSON string!"); break; case JSMN_ERROR_PART: - LOG(USCXML_ERROR) << "Cannot parse JSON, the string is not a full JSON packet, more bytes expected!"; + throw ErrorEvent("Cannot parse JSON, the string is not a full JSON packet, more bytes expected!"); break; default: break; diff --git a/src/uscxml/plugins/DataModelImpl.h b/src/uscxml/plugins/DataModelImpl.h index 9ee1ed1..e93361d 100644 --- a/src/uscxml/plugins/DataModelImpl.h +++ b/src/uscxml/plugins/DataModelImpl.h @@ -23,6 +23,7 @@ #include "uscxml/Common.h" #include "uscxml/plugins/Invoker.h" #include "uscxml/plugins/IOProcessor.h" +#include "uscxml/interpreter/Logging.h" namespace XERCESC_NS { class DOMDocument; @@ -52,6 +53,7 @@ public: virtual bool isInState(const std::string& stateId) = 0; virtual XERCESC_NS::DOMDocument* getDocument() const = 0; virtual const std::map<std::string, Invoker>& getInvokers() = 0; + virtual Logger getLogger() = 0; }; class USCXML_API DataModelExtension { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index f916ae9..283372d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -485,27 +485,27 @@ Data V8DataModel::getValueAsData(const v8::Local<v8::Value>& value, std::set<v8: } else if (value->IsBoolean()) { data.atom = (value->ToBoolean()->Value() ? "true" : "false"); } else if (value->IsBooleanObject()) { - LOG(USCXML_ERROR) << "IsBooleanObject is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsBooleanObject is unimplemented" << std::endl; } else if (value->IsDate()) { - LOG(USCXML_ERROR) << "IsDate is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsDate is unimplemented" << std::endl; } else if (value->IsExternal()) { - LOG(USCXML_ERROR) << "IsExternal is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsExternal is unimplemented" << std::endl; } else if (value->IsFalse()) { - LOG(USCXML_ERROR) << "IsFalse is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsFalse is unimplemented" << std::endl; } else if (value->IsFunction()) { - LOG(USCXML_ERROR) << "IsFunction is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsFunction is unimplemented" << std::endl; } else if (value->IsInt32()) { int32_t prop = value->Int32Value(); data.atom = toStr(prop); } else if (value->IsNativeError()) { - LOG(USCXML_ERROR) << "IsNativeError is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsNativeError is unimplemented" << std::endl; } else if (value->IsNull()) { - LOG(USCXML_ERROR) << "IsNull is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsNull is unimplemented" << std::endl; } else if (value->IsNumber()) { v8::String::AsciiValue prop(v8::Local<v8::String>::Cast(v8::Local<v8::Number>::Cast(value))); data.atom = *prop; } else if (value->IsNumberObject()) { - LOG(USCXML_ERROR) << "IsNumberObject is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsNumberObject is unimplemented" << std::endl; } else if (value->IsObject()) { // if (V8ArrayBuffer::hasInstance(value)) { @@ -529,21 +529,21 @@ Data V8DataModel::getValueAsData(const v8::Local<v8::Value>& value, std::set<v8: data.compound[*key] = getValueAsData(property, alreadySeen); } } else if (value->IsRegExp()) { - LOG(USCXML_ERROR) << "IsRegExp is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsRegExp is unimplemented" << std::endl; } else if(value->IsString()) { v8::String::AsciiValue property(v8::Local<v8::String>::Cast(value)); data.atom = *property; data.type = Data::VERBATIM; } else if(value->IsStringObject()) { - LOG(USCXML_ERROR) << "IsStringObject is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsStringObject is unimplemented" << std::endl; } else if(value->IsTrue()) { - LOG(USCXML_ERROR) << "IsTrue is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsTrue is unimplemented" << std::endl; } else if(value->IsUint32()) { - LOG(USCXML_ERROR) << "IsUint32 is unimplemented" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "IsUint32 is unimplemented" << std::endl; } else if(value->IsUndefined()) { data.atom = "undefined"; } else { - LOG(USCXML_ERROR) << "Value's type is unknown!" << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << "Value's type is unknown!" << std::endl; } return data; } diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index 55c4501..2ad89b5 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -204,7 +204,7 @@ std::shared_ptr<DataModelImpl> LuaDataModel::create(DataModelCallbacks* callback luabridge::setGlobal(dm->_luaState, resultLxpLOM, "lxp.lom"); } } catch (luabridge::LuaException e) { - LOG(USCXML_INFO) << e.what(); + LOG(_callbacks->getLogger(), USCXML_INFO) << e.what(); } luabridge::getGlobalNamespace(dm->_luaState).beginClass<LuaDataModel>("DataModel").endClass(); diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp index a13dd07..a524c7e 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp @@ -193,7 +193,7 @@ void PromelaDataModel::setEvent(const Event& event) { try { PromelaParser parser(expr); } catch (Event e) { - LOG(USCXML_ERROR) << e << std::endl; + LOG(_callbacks->getLogger(), USCXML_ERROR) << e << std::endl; return false; } return true; diff --git a/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.cpp b/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.cpp index de5994a..d6d0f99 100644 --- a/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.cpp +++ b/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.cpp @@ -99,7 +99,7 @@ void DirMonInvoker::eventFromSCXML(const Event& event) { void DirMonInvoker::invoke(const std::string& source, const Event& req) { if (req.params.find("dir") == req.params.end()) { - LOG(USCXML_ERROR) << "No dir param given"; + LOG(_interpreter->getLogger(), USCXML_ERROR) << "No dir param given"; return; } @@ -137,7 +137,7 @@ void DirMonInvoker::invoke(const std::string& source, const Event& req) { URL url = URL::resolve(dirIter->second.atom, _interpreter->getBaseURL()); if (!url.isAbsolute()) { - LOG(USCXML_ERROR) << "Given directory '" << dirIter->second << "' cannot be transformed to absolute path"; + LOG(_interpreter->getLogger(), USCXML_ERROR) << "Given directory '" << dirIter->second << "' cannot be transformed to absolute path"; } else { _dir = url.path(); } @@ -145,6 +145,7 @@ void DirMonInvoker::invoke(const std::string& source, const Event& req) { } _watcher = new DirectoryWatch(_dir, _recurse); + _watcher->setLogger(_interpreter->getLogger()); _watcher->addMonitor(this); _watcher->updateEntries(true); @@ -313,7 +314,7 @@ void DirectoryWatch::updateEntries(bool reportAsExisting) { // stat directory for modification date struct stat dirStat; if (stat((_dir + _relDir).c_str(), &dirStat) != 0) { - LOG(USCXML_ERROR) << "Error with stat on directory " << _dir << ": " << strerror(errno); + LOG(_logger, USCXML_ERROR) << "Error with stat on directory " << _dir << ": " << strerror(errno); return; } @@ -327,7 +328,7 @@ void DirectoryWatch::updateEntries(bool reportAsExisting) { DIR *dp; dp = opendir((_dir + _relDir).c_str()); if (dp == NULL) { - LOG(USCXML_ERROR) << "Error opening directory " << _dir + _relDir << ": " << strerror(errno); + LOG(_logger, USCXML_ERROR) << "Error opening directory " << _dir + _relDir << ": " << strerror(errno); return; } // iterate all entries and see what changed @@ -352,7 +353,7 @@ void DirectoryWatch::updateEntries(bool reportAsExisting) { struct stat fileStat; if (stat(filename.c_str(), &fileStat) != 0) { - LOG(USCXML_ERROR) << "Error with stat on directory entry: " << filename << ": " << strerror(errno); + LOG(_logger, USCXML_ERROR) << "Error with stat on directory entry: " << filename << ": " << strerror(errno); continue; } diff --git a/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.h b/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.h index 6e13864..e6bb9aa 100644 --- a/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.h +++ b/src/uscxml/plugins/invoker/dirmon/DirMonInvoker.h @@ -73,11 +73,16 @@ public: return entries; } + void setLogger(Logger logger) { + _logger = logger; + } + protected: DirectoryWatch(const std::string& dir, const std::string& relDir) : _dir(dir), _relDir(relDir), _recurse(true), _lastChecked(0) {} std::string _dir; std::string _relDir; + Logger _logger; bool _recurse; std::map<std::string, struct stat> _knownEntries; diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp index 82e5cef..ab16887 100644 --- a/src/uscxml/server/HTTPServer.cpp +++ b/src/uscxml/server/HTTPServer.cpp @@ -93,9 +93,9 @@ HTTPServer::HTTPServer(unsigned short port, unsigned short wsPort, SSLConfig* ss if (_port > 0) { _httpHandle = evhttp_bind_socket_with_handle(_http, NULL, _port); if (_httpHandle) { - LOG(USCXML_INFO) << "HTTP server listening on tcp/" << _port; + LOGD(USCXML_INFO) << "HTTP server listening on tcp/" << _port; } else { - LOG(USCXML_ERROR) << "HTTP server cannot bind to tcp/" << _port; + LOGD(USCXML_ERROR) << "HTTP server cannot bind to tcp/" << _port; } } @@ -103,9 +103,9 @@ HTTPServer::HTTPServer(unsigned short port, unsigned short wsPort, SSLConfig* ss if (_wsPort > 0) { _wsHandle = evws_bind_socket(_evws, _wsPort); if (_wsHandle) { - LOG(USCXML_INFO) << "WebSocket server listening on tcp/" << _wsPort; + LOGD(USCXML_INFO) << "WebSocket server listening on tcp/" << _wsPort; } else { - LOG(USCXML_ERROR) << "WebSocket server cannot bind to tcp/" << _wsPort; + LOGD(USCXML_ERROR) << "WebSocket server cannot bind to tcp/" << _wsPort; } } @@ -462,7 +462,7 @@ void HTTPServer::processByMatchingServlet(const Request& request) { matchesIter++; } - LOG(USCXML_INFO) << "Got an HTTP request at " << actualPath << " but no servlet is registered there or at a prefix"; + LOGD(USCXML_INFO) << "Got an HTTP request at " << actualPath << " but no servlet is registered there or at a prefix"; evhttp_send_error(request.evhttpReq, 404, NULL); } @@ -505,7 +505,7 @@ void HTTPServer::replyCallback(evutil_socket_t fd, short what, void *arg) { Reply* reply = (Reply*)arg; if (reply->content.size() > 0 && reply->headers.find("Content-Type") == reply->headers.end()) { - LOG(USCXML_INFO) << "Sending content without Content-Type header"; + LOGD(USCXML_INFO) << "Sending content without Content-Type header"; } std::map<std::string, std::string>::const_iterator headerIter = reply->headers.begin(); @@ -565,7 +565,7 @@ bool HTTPServer::registerServlet(const std::string& path, HTTPServlet* servlet) HTTPServer* INSTANCE = getInstance(); if (!INSTANCE->_httpHandle) { - LOG(USCXML_INFO) << "Registering at unstarted HTTP Server"; + LOGD(USCXML_INFO) << "Registering at unstarted HTTP Server"; return true; // this is the culprit! } @@ -702,7 +702,7 @@ void HTTPServer::run(void* instance) { while(INSTANCE->_isRunning) { event_base_dispatch(INSTANCE->_base); } - LOG(USCXML_INFO) << "HTTP Server stopped"; + LOGD(USCXML_INFO) << "HTTP Server stopped"; } void HTTPServer::determineAddress() { diff --git a/src/uscxml/transform/ChartToPromela.cpp b/src/uscxml/transform/ChartToPromela.cpp index 48037c0..ec11a76 100644 --- a/src/uscxml/transform/ChartToPromela.cpp +++ b/src/uscxml/transform/ChartToPromela.cpp @@ -694,7 +694,7 @@ void ChartToPromela::writeVariables(std::ostream& stream) { if (allTypes.types.find(identifier) != allTypes.types.end()) { type = allTypes.types[identifier].name; } else { - LOG(USCXML_ERROR) << "Automatic or no type for '" << identifier << "' but no type resolved"; + LOGD(USCXML_ERROR) << "Automatic or no type for '" << identifier << "' but no type resolved"; continue; } } diff --git a/src/uscxml/util/DOM.cpp b/src/uscxml/util/DOM.cpp index 9540d04..bc628b7 100644 --- a/src/uscxml/util/DOM.cpp +++ b/src/uscxml/util/DOM.cpp @@ -146,7 +146,7 @@ std::string DOMUtils::xPathForNode(const DOMNode* node, const std::string& ns) { case DOMNode::DOCUMENT_NODE: return xPath; default: - LOG(USCXML_ERROR) << "Only nodes of type element supported for now"; + throw ErrorEvent("Only nodes of type element supported for now"); return ""; break; } diff --git a/src/uscxml/util/URL.cpp b/src/uscxml/util/URL.cpp index b9d7bc3..0885b47 100644 --- a/src/uscxml/util/URL.cpp +++ b/src/uscxml/util/URL.cpp @@ -276,7 +276,7 @@ CURL* URLImpl::getCurlHandle() { if (_handle == NULL) { _handle = curl_easy_init(); if (_handle == NULL) - LOG(USCXML_ERROR) << "curl_easy_init returned NULL, this is bad!"; + throw ErrorEvent("curl_easy_init returned NULL, this is bad!"); } return _handle; } @@ -613,7 +613,7 @@ void URLFetcher::fetchURL(URL& url) { std::string fromURL(url); (curlError = curl_easy_setopt(handle, CURLOPT_URL, fromURL.c_str())) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot set url to " << std::string(url) << ": " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot set url to " << std::string(url) << ": " << curl_easy_strerror(curlError); // (curlError = curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1)) == CURLE_OK || // LOG(USCXML_ERROR) << "Cannot set curl to ignore signals: " << curl_easy_strerror(curlError); @@ -625,37 +625,37 @@ void URLFetcher::fetchURL(URL& url) { // LOG(USCXML_ERROR) << "Cannot set verbose: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(handle, CURLOPT_WRITEDATA, url._impl.get())) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot register this as write userdata: " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot register this as write userdata: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, URLImpl::writeHandler)) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot set write callback: " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot set write callback: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, URLImpl::headerHandler)) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot request header from curl: " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot request header from curl: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(handle, CURLOPT_HEADERDATA, url._impl.get())) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot register this as header userdata: " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot register this as header userdata: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, false)) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot forfeit peer verification: " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot forfeit peer verification: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(handle, CURLOPT_USERAGENT, "uscxml/" USCXML_VERSION)) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot set our user agent string: " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot set our user agent string: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, true)) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot enable follow redirects: " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot enable follow redirects: " << curl_easy_strerror(curlError); if (instance->_envProxy) (curlError = curl_easy_setopt(handle, CURLOPT_PROXY, instance->_envProxy)) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot set curl proxy: " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot set curl proxy: " << curl_easy_strerror(curlError); if (url._impl->_requestType == URLRequestType::POST) { (curlError = curl_easy_setopt(handle, CURLOPT_POST, 1)) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot set request type to post for " << std::string(url) << ": " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot set request type to post for " << std::string(url) << ": " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(handle, CURLOPT_COPYPOSTFIELDS, url._impl->_outContent.c_str())) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot set post data " << std::string(url) << ": " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot set post data " << std::string(url) << ": " << curl_easy_strerror(curlError); // Disable "Expect: 100-continue" // curl_slist* disallowed_headers = 0; @@ -685,14 +685,14 @@ void URLFetcher::fetchURL(URL& url) { instance->_handlesToHeaders[handle] = headers; (curlError = curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers)) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot headers for " << std::string(url) << ": " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot headers for " << std::string(url) << ": " << curl_easy_strerror(curlError); // curl_slist_free_all(headers); } else if (url._impl->_requestType == URLRequestType::GET) { (curlError = curl_easy_setopt(handle, CURLOPT_HTTPGET, 1)) == CURLE_OK || - LOG(USCXML_ERROR) << "Cannot set request type to get for " << std::string(url) << ": " << curl_easy_strerror(curlError); + LOGD(USCXML_ERROR) << "Cannot set request type to get for " << std::string(url) << ": " << curl_easy_strerror(curlError); } url._impl->downloadStarted(); @@ -742,7 +742,7 @@ void URLFetcher::run(void* instance) { while(fetcher->_isStarted) { fetcher->perform(); } - LOG(USCXML_ERROR) << "URLFetcher thread stopped!"; + LOGD(USCXML_ERROR) << "URLFetcher thread stopped!"; } void URLFetcher::perform() { @@ -759,7 +759,7 @@ void URLFetcher::perform() { } err = curl_multi_perform(_multiHandle, &stillRunning); if (err != CURLM_OK) { - LOG(USCXML_WARN) << "curl_multi_perform: " << curl_multi_strerror(err); + LOGD(USCXML_WARN) << "curl_multi_perform: " << curl_multi_strerror(err); } } @@ -783,7 +783,7 @@ void URLFetcher::perform() { std::lock_guard<std::recursive_mutex> lock(_mutex); err = curl_multi_timeout(_multiHandle, &curlTimeOut); if (err != CURLM_OK) { - LOG(USCXML_WARN) << "curl_multi_timeout: " << curl_multi_strerror(err); + LOGD(USCXML_WARN) << "curl_multi_timeout: " << curl_multi_strerror(err); } } @@ -801,7 +801,7 @@ void URLFetcher::perform() { std::lock_guard<std::recursive_mutex> lock(_mutex); err = curl_multi_fdset(_multiHandle, &fdread, &fdwrite, &fdexcep, &maxfd); if (err != CURLM_OK) { - LOG(USCXML_WARN) << "curl_multi_fdset: " << curl_multi_strerror(err); + LOGD(USCXML_WARN) << "curl_multi_fdset: " << curl_multi_strerror(err); } } @@ -816,7 +816,7 @@ void URLFetcher::perform() { std::lock_guard<std::recursive_mutex> lock(_mutex); err = curl_multi_perform(_multiHandle, &stillRunning); if (err != CURLM_OK) { - LOG(USCXML_WARN) << "curl_multi_perform: " << curl_multi_strerror(err); + LOGD(USCXML_WARN) << "curl_multi_perform: " << curl_multi_strerror(err); } break; } @@ -831,7 +831,7 @@ void URLFetcher::perform() { _handlesToURLs[msg->easy_handle]._impl->downloadCompleted(); err = curl_multi_remove_handle(_multiHandle, msg->easy_handle); if (err != CURLM_OK) { - LOG(USCXML_WARN) << "curl_multi_remove_handle: " << curl_multi_strerror(err); + LOGD(USCXML_WARN) << "curl_multi_remove_handle: " << curl_multi_strerror(err); } break; @@ -839,7 +839,7 @@ void URLFetcher::perform() { _handlesToURLs[msg->easy_handle]._impl->downloadFailed(msg->data.result); err = curl_multi_remove_handle(_multiHandle, msg->easy_handle); if (err != CURLM_OK) { - LOG(USCXML_WARN) << "curl_multi_remove_handle: " << curl_multi_strerror(err); + LOGD(USCXML_WARN) << "curl_multi_remove_handle: " << curl_multi_strerror(err); } break; @@ -849,7 +849,7 @@ void URLFetcher::perform() { _handlesToHeaders.erase(msg->easy_handle); } else { - LOG(USCXML_ERROR) << "Curl reports info on unfinished download?!"; + LOGD(USCXML_ERROR) << "Curl reports info on unfinished download?!"; } } } diff --git a/test/src/test-gen-c.cpp b/test/src/test-gen-c.cpp index 2931a13..acf1246 100644 --- a/test/src/test-gen-c.cpp +++ b/test/src/test-gen-c.cpp @@ -55,6 +55,10 @@ public: init(); } + virtual Logger getLogger() { + return Logger::getDefault(); + } + const std::string& getName() { return name; } diff --git a/test/src/test-stress.cpp b/test/src/test-stress.cpp index d3253b4..afb94a6 100644 --- a/test/src/test-stress.cpp +++ b/test/src/test-stress.cpp @@ -79,7 +79,7 @@ int main(int argc, char** argv) { Interpreter interpreter = Interpreter::fromURL(std::string(argv[optind]) + PATH_SEPERATOR + entryIter->first); // Interpreter interpreter = Interpreter::fromURL("/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma/test422.scxml"); - LOG(USCXML_INFO) << "Processing " << interpreter.getImpl()->getBaseURL(); + LOGD(USCXML_INFO) << "Processing " << interpreter.getImpl()->getBaseURL(); if (interpreter) { interpreter.addMonitor(&vm); diff --git a/test/src/test-url.cpp b/test/src/test-url.cpp index 94c47e9..4d6cee8 100644 --- a/test/src/test-url.cpp +++ b/test/src/test-url.cpp @@ -145,7 +145,7 @@ int main(int argc, char** argv) { try {
testFileURLs();
} catch (Event e) {
- LOG(USCXML_ERROR) << e;
+ LOGD(USCXML_ERROR) << e;
exit(EXIT_FAILURE);
}
|