Branch data Line data Source code
1 : : // ----------------- BEGIN LICENSE BLOCK --------------------------------- 2 : : // 3 : : // Copyright (C) 2019-2021 Intel Corporation 4 : : // 5 : : // SPDX-License-Identifier: LGPL-2.1-only 6 : : // 7 : : // ----------------- END LICENSE BLOCK ----------------------------------- 8 : : 9 : : #include "ad/rss/core/Logging.hpp" 10 : : 11 : : #include <spdlog/sinks/stdout_color_sinks.h> 12 : : 13 : : namespace ad { 14 : : namespace rss { 15 : : namespace core { 16 : : 17 : : class Logging 18 : : { 19 : : public: 20 : : static Logging &instance(); 21 : : 22 : : std::shared_ptr<spdlog::logger> mLogger; 23 : : 24 : : private: 25 : : // Copy operators and constructors are deleted to avoid accidental copies 26 : : Logging(Logging const &) = delete; 27 : : Logging(Logging const &&) = delete; 28 : : Logging &operator=(Logging &&) = delete; 29 : : Logging &operator=(Logging const &) = delete; 30 : : 31 : : explicit Logging(); 32 : : ~Logging(); 33 : : }; 34 : : 35 : 39416 : Logging &Logging::instance() 36 : : { 37 [ + + + - : 39416 : static Logging singleton; + - - - ] 38 : 39416 : return singleton; 39 : : } 40 : : 41 : 2 : Logging::Logging() 42 : : { 43 [ + - + - ]: 2 : mLogger = spdlog::stdout_color_mt("rss_core"); 44 : 2 : } 45 : : 46 : 2 : Logging::~Logging() 47 : : { 48 : 2 : } 49 : : 50 : 39416 : std::shared_ptr<spdlog::logger> getLogger() 51 : : { 52 : 39416 : return Logging::instance().mLogger; 53 : : } 54 : : 55 : 0 : spdlog::level::level_enum getLogLevel() 56 : : { 57 [ # # ]: 0 : return getLogger()->level(); 58 : : } 59 : : 60 : 0 : void setLogLevel(spdlog::level::level_enum const logLevel) 61 : : { 62 [ # # ]: 0 : getLogger()->set_level(logLevel); 63 : 0 : } 64 : : 65 : 0 : void setLogLevel(std::string const &logLevel) 66 : : { 67 [ # # ]: 0 : getLogger()->set_level(spdlog::level::from_str(logLevel)); 68 : 0 : } 69 : : 70 : : } // namespace core 71 : : } // namespace rss 72 : : } // namespace ad