Pantheios在C++中设置显示级别

use*_*957 1 c++ logging pantheios log-level

我正在使用Pantheios库进行日志记录.我有:

pantheios::log(pantheios::debug, "I'm debug");
pantheios::log(pantheios::informational, "Some info");
Run Code Online (Sandbox Code Playgroud)

哪个输出:

[MyApplication, Jun 14 15:45:26.549; Debug] : I'm debug
[MyApplication.1, Jun 14 15:45:26.549; Informational] : Some info
Run Code Online (Sandbox Code Playgroud)

但我想在显示信息和调试之间做出选择:

 set_level(pantheios::informational) //what should this be ?
 pantheios::log(pantheios::debug, "I'm debug");
 pantheios::log(pantheios::informational, "Some info");
Run Code Online (Sandbox Code Playgroud)

哪个输出:

[MyApplication.1, Jun 14 15:45:26.549; Informational] : Some info
Run Code Online (Sandbox Code Playgroud)

Eit*_*n T 5

实际过滤日志级别的"正确"方法是自定义记录器前端和覆盖pantheios::pantheios_fe_isSevereityLogged(),这些内容如下:

namespace
{
    static int s_log_level = pantheios::debug;
}

PANTHEIOS_CALL(int) pantheios_fe_isSeverityLogged(void *token,
    int severity, int backEndId)
{
    return severity <= s_log_level;
}
Run Code Online (Sandbox Code Playgroud)

你应该参考这个这个例子中获取更多信息.