clutchlog/tests/t-log.cpp
nojhan 76e4782cb0 feat(levels): easier threshold setting.
- Adds `threshold(string)` for easier level setting.
- Adds `levels()` to make it easy to test if a user-defined string is good.
- Move the log levels section up in the readme.
2022-08-29 10:24:17 +02:00

70 lines
1.6 KiB
C++

#include <iostream>
#include "../clutchlog/clutchlog.h"
void h()
{
CLUTCHLOG(info, "!");
std::clog << "--" << std::endl;
}
void g()
{
CLUTCHLOG(warning, "world");
h();
}
void f()
{
CLUTCHLOG(error, "hello ");
g();
}
int main(/*const int argc, char* argv[]*/)
{
auto& log = clutchlog::logger();
log.out(std::clog);
std::clog << "depth: 99; threshold: xdebug; location: .*" << std::endl;
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
log.depth(99);
#endif
log.threshold(clutchlog::level::xdebug);
log.location(".*",".*");
f();
std::clog << "depth: 4; threshold: xdebug; location: ,*" << std::endl;
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
log.depth(4);
#endif
assert(log.levels().find("XDebug") != std::end(log.levels())); // contains
assert(log.levels().find("Xdebug") == std::end(log.levels())); // not contains
log.threshold("XDebug");
log.location(".*");
f();
std::clog << "depth: 99; threshold: warning; location: .*" << std::endl;
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
log.depth(99);
#endif
log.threshold(clutchlog::level::warning);
log.location(".*");
f();
std::clog << "depth: 99; threshold: xdebug; location: 'core','g'" << std::endl;
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
log.depth(99);
#endif
log.threshold(clutchlog::level::xdebug);
log.location("core","g");
f();
std::clog << "depth: 99; threshold: debug; location: '.*','(g|h)'" << std::endl;
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
log.depth(99);
#endif
log.threshold("Debug");
log.location(".*","(g|h)");
f();
}