Commit 9e504b33 by guanghui.cui

添加日志管理模块

parent 657616e5
......@@ -93,6 +93,17 @@ void get_userinfo_by_phone(IN const string &phone, OUT adStruct &info);
// 广告播放推送
CURLcode curl_post_ad(const string &url, const string equipmentId,const string productId, string &response);
void logRolloutHandler(const char* filename, std::size_t size)
{
/// 备份日志
//std::string strLogPath = GetProcDir();
//strLogPath.append(filename);
std::cout << "bk filename:" << filename << std::endl;
std::stringstream ss;
ss << "mv " << filename << " " << filename << "_bk";
system(ss.str().c_str());
}
/****************************************
主函数
****************************************/
......@@ -100,6 +111,17 @@ int main(int argc, char** argv)
{
try
{
// 初始化日志
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
std::string strBinPath = GetProcDir();
std::string strLogPath(strBinPath.data());
strLogPath.append("log.conf");
el::Configurations conf(strLogPath.data());
/// 设置全部logger的配置
el::Loggers::reconfigureAllLoggers(conf);
/// 注册回调函数
el::Helpers::installPreRollOutCallback(logRolloutHandler);
LOG(INFO) << "**************START PROCESS****************";
// 读取配置文件信息
std::string strIniPath= GetProcDir();
......@@ -250,6 +272,9 @@ int main(int argc, char** argv)
// global release
curl_global_cleanup();
// 注销回调函数
el::Helpers::uninstallPreRollOutCallback();
return 0;
}
......@@ -386,6 +411,7 @@ void reqUserInfoByImg(int index, string &imgPath)
std::string postAdResponseStr;
curl_post_ad(strAdUrl, strDeviceId, adInfo.goodsId, postAdResponseStr);
//curl_post_ad(strAdUrl,"6739c9fa37f547ef916d06d33a73331a","80052478", postAdResponseStr);
LOG(INFO) << "push data device_id:" << strDeviceId.data()<<" goods_id:"<< adInfo.goodsId.data();
LOG(INFO) <<"ad push response:" <<postAdResponseStr.data();
}
}
......
* GLOBAL:
ENABLED = true
TO_FILE = true
TO_STANDARD_OUTPUT = true
FORMAT = "[%level | %datetime] | %msg"
FILENAME = "./logs/log.log"
MILLISECONDS_WIDTH = 3
PERFORMANCE_TRACKING = false
MAX_LOG_FILE_SIZE = 10485760
LOG_FLUSH_THRESHOLD = 10
* TRACE:
FILENAME = "./logs/trace_log.log"
* DEBUG:
FILENAME = "./logs/debug_log.log"
* FATAL:
ENABLED = false
* ERROR:
FILENAME = "./logs/error_log.log"
* WARNING:
FILENAME = "./logs/warning_log.log"
* INFO:
FILENAME = "./logs/info_log.log"
* VERBOSE:
ENABLED = false
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment