mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
update logger.cpp/h
This commit is contained in:
parent
55d1f0664f
commit
1e0872c422
@ -28,14 +28,14 @@ file_functs.ut: file_functs.cpp file_functs.h
|
||||
io_functs.test: io_functs.cpp io_functs.h
|
||||
g++ -o $@ $< -DTEST_IO_FUNCTS
|
||||
str_functs.ut: str_functs.cpp str_functs.h
|
||||
g++ -o $@ $< -DTEST_STR_FUNCTS -liconv
|
||||
g++ -o $@ $< -DTEST_STR_FUNCTS
|
||||
encoding.ut: encoding.cpp str_functs.cpp str_functs.h encoding.h
|
||||
g++ -o $@ encoding.cpp str_functs.cpp -DENCODING_UT -liconv
|
||||
g++ -o $@ encoding.cpp str_functs.cpp -DENCODING_UT
|
||||
vec_functs.test: vec_functs.cpp vec_functs.h vec_functs.tcc
|
||||
g++ -o $@ $< -DTEST_VEC_FUNCTS
|
||||
|
||||
logger.ut: logger.cpp logger.h file_functs.cpp file_functs.h str_functs.cpp str_functs.h
|
||||
g++ -o $@ $< file_functs.cpp str_functs.cpp -DLOGGER_UT -liconv
|
||||
g++ -o $@ $< file_functs.cpp str_functs.cpp -DLOGGER_UT
|
||||
config.ut: config.cpp config.h
|
||||
g++ -o $@ $< -DCONFIG_UT $(CMLIB)
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "logger.h"
|
||||
namespace CPPCOMMON
|
||||
{
|
||||
const char * Logger::_logFormat = "%s [File:%s] [Line:%d] [%s] Msg:%s";
|
||||
const char * Logger::_logFormat = "%s [File:%s] [Line:%d] [%s] Msg:%s\n";
|
||||
const char * Logger::_timeFormat = "%Y-%m-%d %H:%M:%S";
|
||||
Logger::Logger()
|
||||
{
|
||||
@ -21,7 +21,7 @@ namespace CPPCOMMON
|
||||
{
|
||||
}
|
||||
|
||||
bool Logger::Logging(uint level, const string& msg, const char* fileName, int lineNo)
|
||||
bool Logger::Logging(uint level, const char * msg, const char* fileName, int lineNo)
|
||||
{
|
||||
if(level > LL_FATAL)
|
||||
{
|
||||
@ -32,16 +32,17 @@ namespace CPPCOMMON
|
||||
size_t ret = strftime(_cStrBuf, sizeof(_cStrBuf), _timeFormat, localtime(&_timeNow));
|
||||
if(0 == ret)
|
||||
{
|
||||
cerr<<"strftime failed."<<endl;
|
||||
fprintf(stderr, "stftime failed.\n");
|
||||
return false;
|
||||
}
|
||||
if(level >= LL_WARN)
|
||||
{
|
||||
cerr<<string_format(_logFormat, _cStrBuf, fileName, lineNo, _logLevel[level], msg.c_str())<<endl;
|
||||
fprintf(stderr, _logFormat, _cStrBuf, fileName, lineNo, _logLevel[level], msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<string_format(_logFormat, _cStrBuf, fileName, lineNo, _logLevel[level], msg.c_str())<<endl;
|
||||
fprintf(stdout, _logFormat, _cStrBuf, fileName, lineNo, _logLevel[level], msg);
|
||||
fflush(stdout);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ namespace CPPCOMMON
|
||||
Logger();
|
||||
~Logger();
|
||||
public:
|
||||
bool Logging(uint level, const string& msg, const char* fileName, int lineNo);
|
||||
bool Logging(uint level, const char * msg, const char* fileName, int lineNo);
|
||||
private:
|
||||
char _cStrBuf[CSTR_BUFFER_SIZE];
|
||||
const char * _logLevel[LEVEL_ARRAY_SIZE];
|
||||
|
Loading…
x
Reference in New Issue
Block a user