mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
update LogFatal, print more readable error message when errors happened
This commit is contained in:
parent
56c524f7a8
commit
b70875f412
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<string> 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<string> 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))
|
||||
{
|
||||
|
@ -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<string> 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))
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user