12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #pragma once
- #include <glog/logging.h>
- #include "tool/pathcreator.hpp"
- namespace ZX{
- static void shut_down_logging(const char *data, size_t size) {
- time_t tt;
- time(&tt);
- tt = tt + 8 * 3600; // transform the time zone
- tm *t = gmtime(&tt);
- char buf[255] = {0};
- sprintf(buf, "./%d%02d%02d-%02d%02d%02d-dump.txt",
- t->tm_year + 1900,
- t->tm_mon + 1,
- t->tm_mday,
- t->tm_hour,
- t->tm_min,
- t->tm_sec);
- FILE *tp_file = fopen(buf, "w");
- fprintf(tp_file, data, strlen(data));
- fclose(tp_file);
- }
- // 例子: ZX::InitGlog(PROJECT_NAME, ETC_PATH PROJECT_NAME "/LogInfo/");
- static bool InitGlog(const char * project_name, const char *logPath) {
- PathCreator pc;
- if (!pc.Mkdir(logPath)) {return false;}
- google::InitGoogleLogging(project_name);
- google::SetStderrLogging(google::INFO);
- google::SetLogDestination(google::INFO, logPath);
- google::SetLogFilenameExtension(".log");
- google::InstallFailureSignalHandler();
- google::InstallFailureWriter(&ZX::shut_down_logging);
- FLAGS_colorlogtostderr = true; // Set log color
- FLAGS_logbufsecs = 0; // Set log output speed(s)
- FLAGS_max_log_size = 32; // Set max log file size(MB)
- FLAGS_stop_logging_if_full_disk = true;
- return true;
- }
- }
|