欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

glog使用

程序员文章站 2022-03-20 13:58:15
...
#include "widget.h"
#include <QApplication>
#include <QtWidgets>
#include <glog/logging.h>
using namespace google;

void set_log_dir_1(const char *dst_folder) {
    google::SetLogDestination(google::INFO, (std::string(dst_folder) + "INFO").c_str());
    google::SetLogDestination(google::WARNING, (std::string(dst_folder) + "WARNING").c_str());
    google::SetLogDestination(google::ERROR, (std::string(dst_folder) + "ERROR").c_str());
}

void set_log_dir_2(const char *dst_folder) {
    FLAGS_log_dir = dst_folder;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    google::InitGoogleLogging(argv[0]);
    set_log_dir_2("./log");
    FLAGS_stderrthreshold = google::FATAL;
    FLAGS_minloglevel = google::INFO;
    FLAGS_logbuflevel = google::ERROR;
    FLAGS_stop_logging_if_full_disk = true;
    FLAGS_max_log_size = 1;
    FLAGS_logtostderr = true; // 不输出到文件,输出到stderr.

    int i = 0;
    while (i++ < 1000) {
        LOG(INFO) << "I am INFO!";
        LOG(WARNING) << "I am WARNING!";
        LOG(ERROR) << "I am ERROR!";
        DLOG(INFO)<<"I am DLOG";
        // LOG(FATAL) << "I am FATAL!";
    }
    google::ShutdownGoogleLogging();
    return a.exec();
}