loglevel.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2024-2025 Marek Küthe <m.k@mk16.de> 2 // 3 // SPDX-License-Identifier: GPL-3.0-or-later 4 5 #include "loglevel.hpp" 6 7 LogLevel::LogLevel(boost::log::trivial::severity_level log_level) : 8 _log_level(log_level) 9 { 10 } 11 12 LogLevel::LogLevel(const std::string_view log_level_string) 13 { 14 if (log_level_string == "trace") 15 { 16 this->_log_level = boost::log::trivial::trace; 17 } 18 else if (log_level_string == "debug") 19 { 20 this->_log_level = boost::log::trivial::debug; 21 } 22 else if (log_level_string == "info") 23 { 24 this->_log_level = boost::log::trivial::info; 25 } 26 else if (log_level_string == "warning") 27 { 28 this->_log_level = boost::log::trivial::warning; 29 } 30 else if (log_level_string == "error") 31 { 32 this->_log_level = boost::log::trivial::error; 33 } 34 else if (log_level_string == "fatal") 35 { 36 this->_log_level = boost::log::trivial::fatal; 37 } 38 else 39 { 40 throw std::runtime_error("Unknown log level"); 41 } 42 } 43 44 const boost::log::trivial::severity_level& 45 LogLevel::get_log_level() const noexcept 46 { 47 return this->_log_level; 48 } 49 50 void LogLevel::apply() const 51 { 52 boost::log::core::get()->set_filter(boost::log::trivial::severity >= 53 this->_log_level); 54 }