plog日志库(c++)

1、下载plog第三方库,解压后放到D盘根目录

2、VS项目属性中引入

 3、使用方法

#include <plog/Log.h> //先引入第三方
#include <iostream> //后引入标准库

int getUserInput()
{
    LOGD << "getUserInput() called"; // 输出到日志的内容

    std::cout << "Enter a number: ";
    int x{};
    std::cin >> x;
    return x;
}

int main()
{
    plog::init(plog::debug, "Logfile.txt"); // 启动日志
    //plog::init(plog::none, "Logfile.txt"); // 关闭日志,LOGD << 不会再写入任何内容
    LOGD << "main() called"; // 输出到日志的内容

    int x{ getUserInput() };
    std::cout << "You entered: " << x;

    return 0;
}

在项目路径中生成Logfile.txt

猜你喜欢

转载自www.cnblogs.com/xixixing/p/13183319.html
今日推荐