mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 04:19:10 -04:00
Improve the test logger
This commit is contained in:
parent
89cc6a9b87
commit
fbc11291fa
@ -23,12 +23,14 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <folly/Conv.h>
|
||||
|
||||
#include "dwarfs/logger.h"
|
||||
#include "dwarfs/util.h"
|
||||
|
||||
namespace dwarfs::test {
|
||||
|
||||
@ -48,9 +50,9 @@ class test_logger : public ::dwarfs::logger {
|
||||
int line;
|
||||
};
|
||||
|
||||
test_logger(level_type threshold = TRACE)
|
||||
: threshold_{threshold}
|
||||
, output_{debug_output_enabled()} {
|
||||
test_logger(std::optional<level_type> threshold = std::nullopt)
|
||||
: threshold_{threshold ? *threshold : default_threshold()}
|
||||
, output_{::dwarfs::getenv_is_enabled("DWARFS_TEST_LOGGER_OUTPUT")} {
|
||||
if (output_ || threshold > level_type::INFO) {
|
||||
set_policy<debug_logger_policy>();
|
||||
} else {
|
||||
@ -79,13 +81,11 @@ class test_logger : public ::dwarfs::logger {
|
||||
void clear() { log_.clear(); }
|
||||
|
||||
private:
|
||||
static bool debug_output_enabled() {
|
||||
if (auto var = std::getenv("DWARFS_TEST_LOGGER_OUTPUT")) {
|
||||
if (auto val = folly::tryTo<bool>(var); val && *val) {
|
||||
return true;
|
||||
}
|
||||
static level_type default_threshold() {
|
||||
if (auto var = std::getenv("DWARFS_TEST_LOGGER_LEVEL")) {
|
||||
return ::dwarfs::logger::parse_level(var);
|
||||
}
|
||||
return false;
|
||||
return level_type::INFO;
|
||||
}
|
||||
|
||||
std::mutex mx_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user