-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathInitGlog.cpp
More file actions
54 lines (43 loc) · 2.38 KB
/
InitGlog.cpp
File metadata and controls
54 lines (43 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "include/InitGlog.h"
#include "include/glog/logging.h"
#include <iostream>
using namespace std;
string &replace_all(string &str, const string &old_value, const string &new_value);
void init_glog(string log_folder,string log_subFolder,string glogLevel) {
string logName = log_subFolder;//string("smart_proxy_center");
try {
google::InitGoogleLogging(logName.c_str());
} catch (std::exception &e) {
}
string str_smart_log_folder = log_folder + string("/") + log_subFolder;//string("/smartcpplog");
FLAGS_log_dir = str_smart_log_folder.c_str();
if (glogLevel == "INFO") {
FLAGS_minloglevel = 0;
}else if (glogLevel == "WARNING") {
FLAGS_minloglevel = 1;
}else if (glogLevel == "ERROR") {
FLAGS_minloglevel = 2;
}
else {
FLAGS_minloglevel = 0;//default glog level is INFO
}
google::SetStderrLogging(google::GLOG_ERROR);//设置级别高于 google::INFO 的日志同时输出到屏幕
FLAGS_colorlogtostderr = true; //设置输出到屏幕的日志显示相应颜色
FLAGS_stop_logging_if_full_disk = true; //当磁盘被写满时,停止日志输出
//设置日志路径及文件名
string logPathName = str_smart_log_folder + "/" + logName + "_fatal_";
google::SetLogDestination(google::GLOG_FATAL, logPathName.c_str()); // 设置 google::FATAL 级别的日志存储路径和文件名前缀
logPathName = str_smart_log_folder + "/" + logName + "_error_";
google::SetLogDestination(google::GLOG_ERROR, logPathName.c_str()); //设置 google::ERROR 级别的日志存储路径和文件名前缀
logPathName = str_smart_log_folder + "/" + logName + "_warning_";
google::SetLogDestination(google::GLOG_WARNING, logPathName.c_str()); //设置 google::WARNING 级别的日志存储路径和文件名前缀
logPathName = str_smart_log_folder + "/" + logName + "_info_";
google::SetLogDestination(google::GLOG_INFO, logPathName.c_str()); //设置 google::INFO 级别的日志存储路径和文件名前缀
// FLAGS_max_log_size = 1; //单个日志文件最大,单位M 默认1.8G
google::SetDeleteLogBeyondHowLongTimeBySeconds(3600 * 24 * 15); //log最长保留15天
LOG(ERROR) << "XTP JAVA API Log start in folder: " << str_smart_log_folder << ", this is not a error";
}
void shutdown_glog() {
LOG(INFO) << "Shutdown Glog";
google::ShutdownGoogleLogging();
}