mirror of https://github.com/TarsCloud/TarsCpp
rolllog only init once
parent
83630b5bea
commit
5911d2da26
|
@ -204,7 +204,7 @@ public:
|
|||
|
||||
void initialize()
|
||||
{
|
||||
g_group.start(1);
|
||||
g_group.start();
|
||||
|
||||
g_logger.init("./debug", 1024 * 1024, 10);
|
||||
g_logger.modFlag(TC_RollLogger::HAS_LEVEL | TC_RollLogger::HAS_PID, true);
|
||||
|
|
|
@ -127,6 +127,11 @@ void LocalRollLogger::terminate()
|
|||
|
||||
void LocalRollLogger::setLogInfo(const string &sApp, const string &sServer, const string &sLogpath, int iMaxSize, int iMaxNum, const CommunicatorPtr &comm, const string &sLogObj)
|
||||
{
|
||||
if (_local.isStart())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_app = sApp;
|
||||
_server = sServer;
|
||||
_logpath = sLogpath;
|
||||
|
@ -142,7 +147,7 @@ void LocalRollLogger::setLogInfo(const string &sApp, const string &sServer, cons
|
|||
//生成目录
|
||||
TC_File::makeDirRecursive(_logpath + FILE_SEP + _app + FILE_SEP + _server);
|
||||
|
||||
_local.start(1);
|
||||
_local.start();
|
||||
|
||||
//初始化本地循环日志
|
||||
_logger.init(_logpath + FILE_SEP + _app + FILE_SEP + _server + FILE_SEP + _app + "." + _server, iMaxSize, iMaxNum);
|
||||
|
@ -235,8 +240,8 @@ LocalRollLogger::RollLogger *LocalRollLogger::logger(const string &suffix)
|
|||
|
||||
TarsLoggerThread::TarsLoggerThread()
|
||||
{
|
||||
_local.start(1);
|
||||
_remote.start(1);
|
||||
_local.start();
|
||||
_remote.start();
|
||||
}
|
||||
|
||||
TarsLoggerThread::~TarsLoggerThread()
|
||||
|
|
|
@ -297,9 +297,9 @@ namespace tars
|
|||
* @brief 启动线程.
|
||||
* @brief Start Thread
|
||||
*
|
||||
* @param iThreadNum线程数
|
||||
* @param iThreadNum线程数, 无效, 永远为1
|
||||
*/
|
||||
void start(size_t iThreadNum);
|
||||
void start(int iThreadNum = 1);
|
||||
|
||||
/**
|
||||
* @brief 注册logger对象.
|
||||
|
@ -325,8 +325,16 @@ namespace tars
|
|||
*/
|
||||
void flush();
|
||||
|
||||
/**
|
||||
* 结束
|
||||
*/
|
||||
void terminate();
|
||||
|
||||
/**
|
||||
* 是否已经启动了
|
||||
* @return
|
||||
*/
|
||||
bool isStart();
|
||||
protected:
|
||||
/**
|
||||
* @brief 写日志
|
||||
|
|
|
@ -121,7 +121,7 @@ TC_LoggerThreadGroup::~TC_LoggerThreadGroup()
|
|||
terminate();
|
||||
}
|
||||
|
||||
void TC_LoggerThreadGroup::start(size_t iThreadNum)
|
||||
void TC_LoggerThreadGroup::start(int iThreadNum)
|
||||
{
|
||||
if(!_thread)
|
||||
{
|
||||
|
@ -129,6 +129,11 @@ void TC_LoggerThreadGroup::start(size_t iThreadNum)
|
|||
}
|
||||
}
|
||||
|
||||
bool TC_LoggerThreadGroup::isStart()
|
||||
{
|
||||
return _thread.get() != nullptr;
|
||||
}
|
||||
|
||||
void TC_LoggerThreadGroup::registerLogger(TC_LoggerRollPtr &l)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
|
@ -159,6 +164,7 @@ void TC_LoggerThreadGroup::terminate()
|
|||
if (_thread)
|
||||
{
|
||||
_thread->join();
|
||||
_thread.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue