rolllog only init once

pull/294/head
ruanshudong 2023-11-14 16:47:10 +08:00
parent 83630b5bea
commit 5911d2da26
4 changed files with 26 additions and 7 deletions

View File

@ -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);

View File

@ -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()

View File

@ -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

View File

@ -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();
}
}