use global logging level without spdlog

This commit is contained in:
Matthias Hochsteger 2019-09-09 15:13:08 +02:00
parent 6c69df9fe6
commit 66c4c3bf59
3 changed files with 13 additions and 4 deletions

View File

@ -15,12 +15,14 @@ namespace ngcore
{
std::ostream* testout = new std::ostream(nullptr); // NOLINT
level::level_enum Logger::global_level;
void Logger::log(level::level_enum level, std::string && s)
{
#ifdef NETGEN_USE_SPDLOG
logger->log(spdlog::level::level_enum(level), s);
#else // NETGEN_USE_SPDLOG
if(level>level::debug)
if(level>=global_level)
std::clog << s << '\n';
#endif // NETGEN_USE_SPDLOG
}
@ -126,7 +128,11 @@ namespace ngcore
return std::make_shared<Logger>(std::make_shared<spdlog::logger>());
}
void SetLoggingLevel(level::level_enum /*unused*/, const std::string& /*unused*/) {}
void SetLoggingLevel(level::level_enum level, const std::string& /*unused*/)
{
Logger::SetGlobalLoggingLevel(level);
}
void AddFileSink(const std::string& /*unused*/, level::level_enum /*unused*/,
const std::string& /*unused*/)
{}

View File

@ -49,7 +49,11 @@ namespace ngcore
class Logger
{
static NGCORE_API level::level_enum global_level;
public:
static void SetGlobalLoggingLevel( level::level_enum level ) { global_level = level; }
std::shared_ptr<spdlog::logger> logger;
Logger(std::shared_ptr<spdlog::logger> l) : logger(std::move(l)) {}

View File

@ -74,8 +74,7 @@ namespace ngcore
task_manager = new TaskManager();
// TODO: use logger for output
std::cout << "task-based parallelization (C++11 threads) using "<< task_manager->GetNumThreads() << " threads" << std::endl;
GetLogger("TaskManager")->info("task-based parallelization (C++11 threads) using {} threads", task_manager->GetNumThreads());
#ifdef USE_NUMA
numa_run_on_node (0);