diff --git a/server/Husky/WorkerThread.hpp b/server/Husky/WorkerThread.hpp index 3ef6114..08937f2 100644 --- a/server/Husky/WorkerThread.hpp +++ b/server/Husky/WorkerThread.hpp @@ -27,13 +27,13 @@ class WorkerThread: public ITask { void run() { do { if(!_setsockopt(_sockfd)) { - LogFatal("_getsockopt failed."); + LogError("_getsockopt failed."); break; } string strSnd, strRetByHandler; HttpReqInfo httpReq; if(!_receive(_sockfd, httpReq)) { - LogFatal("_receive failed."); + LogError("_receive failed."); break; } diff --git a/src/DictTrie.hpp b/src/DictTrie.hpp index 15b04fb..2e27646 100644 --- a/src/DictTrie.hpp +++ b/src/DictTrie.hpp @@ -47,7 +47,10 @@ namespace CppJieba bool init(const string& dictPath, const string& userDictPath = "") { - assert(!_trie); + if(_trie != NULL) + { + LogFatal("trie already initted"); + } _loadDict(dictPath); _calculateWeight(_nodeInfos); _minWeight = _findMinWeight(_nodeInfos); @@ -104,7 +107,10 @@ namespace CppJieba void _loadUserDict(const string& filePath, double defaultWeight, const string& defaultTag) { ifstream ifs(filePath.c_str()); - assert(ifs.is_open()); + if(!ifs.is_open()) + { + LogFatal("file %s open failed.", filePath.c_str()); + } string line; DictUnit nodeInfo; vector buf; @@ -113,7 +119,10 @@ namespace CppJieba { buf.clear(); split(line, buf, " "); - assert(buf.size() >= 1); + if(buf.size() < 1) + { + LogFatal("split [%s] result illegal", line.c_str()); + } if(!TransCode::decode(buf[0], nodeInfo.word)) { LogError("line[%u:%s] illegal.", lineno, line.c_str()); @@ -132,15 +141,21 @@ namespace CppJieba void _loadDict(const string& filePath) { ifstream ifs(filePath.c_str()); - assert(ifs.is_open()); + if(!ifs.is_open()) + { + LogFatal("file %s open failed.", filePath.c_str()); + } string line; vector buf; DictUnit nodeInfo; - for(size_t lineno = 0 ; getline(ifs, line); lineno++) + for(size_t lineno = 0; getline(ifs, line); lineno++) { split(line, buf, " "); - assert(buf.size() == DICT_COLUMN_NUM); + if(buf.size() != DICT_COLUMN_NUM) + { + LogFatal("split result illegal, line: %s, result size: %u", line.c_str(), buf.size()); + } if(!TransCode::decode(buf[0], nodeInfo.word)) { diff --git a/src/KeywordExtractor.hpp b/src/KeywordExtractor.hpp index 1020be8..a6ed647 100644 --- a/src/KeywordExtractor.hpp +++ b/src/KeywordExtractor.hpp @@ -91,10 +91,9 @@ namespace CppJieba void _loadIdfDict(const string& idfPath) { ifstream ifs(idfPath.c_str()); - if(!ifs) + if(!ifs.is_open()) { - LogError("open %s failed.", idfPath.c_str()); - assert(false); + LogFatal("open %s failed.", idfPath.c_str()); } string line ; vector buf; @@ -127,10 +126,9 @@ namespace CppJieba void _loadStopWordDict(const string& filePath) { ifstream ifs(filePath.c_str()); - if(!ifs) + if(!ifs.is_open()) { - LogError("open %s failed.", filePath.c_str()); - assert(false); + LogFatal("open %s failed.", filePath.c_str()); } string line ; while(getline(ifs, line)) diff --git a/src/Limonp/Logger.hpp b/src/Limonp/Logger.hpp index 14c1438..d46cb9a 100644 --- a/src/Limonp/Logger.hpp +++ b/src/Limonp/Logger.hpp @@ -22,7 +22,7 @@ #define LogInfo(fmt, ...) Limonp::Logger::LoggingF(Limonp::LL_INFO, FILE_BASENAME, __LINE__, fmt, ## __VA_ARGS__) #define LogWarn(fmt, ...) Limonp::Logger::LoggingF(Limonp::LL_WARN, FILE_BASENAME, __LINE__, fmt, ## __VA_ARGS__) #define LogError(fmt, ...) Limonp::Logger::LoggingF(Limonp::LL_ERROR, FILE_BASENAME, __LINE__, fmt, ## __VA_ARGS__) -#define LogFatal(fmt, ...) Limonp::Logger::LoggingF(Limonp::LL_FATAL, FILE_BASENAME, __LINE__, fmt, ## __VA_ARGS__) +#define LogFatal(fmt, ...) {Limonp::Logger::LoggingF(Limonp::LL_FATAL, FILE_BASENAME, __LINE__, fmt, ## __VA_ARGS__); abort();} namespace Limonp { using namespace std;