This commit is contained in:
gabime 2019-12-21 15:54:42 +02:00
parent 68ed281461
commit fc3d18ed64
6 changed files with 32 additions and 39 deletions

View File

@ -25,7 +25,7 @@ void syslog_example();
int main(int args, char *argv[]) int main(int args, char *argv[])
{ {
//spdlog::cfg::init_from_env(); // spdlog::cfg::init_from_env();
spdlog::cfg::init_from_argv(args, argv); spdlog::cfg::init_from_argv(args, argv);
spdlog::info("HELLO INFO"); spdlog::info("HELLO INFO");

View File

@ -9,7 +9,6 @@
// Init levels from argv SPDLOG_LEVEL // Init levels from argv SPDLOG_LEVEL
// Example: my_program.exe "SPDLOG_LEVEL=trace" // Example: my_program.exe "SPDLOG_LEVEL=trace"
namespace spdlog { namespace spdlog {
namespace cfg { namespace cfg {
// search for SPDLOG_LEVEL= in the args and use it to init the levels // search for SPDLOG_LEVEL= in the args and use it to init the levels

View File

@ -8,42 +8,39 @@
#include <unordered_map> #include <unordered_map>
namespace spdlog { namespace spdlog {
namespace cfg { namespace cfg {
class log_levels class log_levels
{
public:
using levels_map = std::unordered_map<std::string, spdlog::level::level_enum>;
void set(const std::string &logger_name, level::level_enum lvl)
{
if (logger_name.empty())
{ {
default_level_ = lvl;
}
else
{
levels_[logger_name] = lvl;
}
}
public: level::level_enum get(const std::string &logger_name)
using levels_map = std::unordered_map<std::string, spdlog::level::level_enum>; {
auto it = levels_.find(logger_name);
return it != levels_.end() ? it->second : default_level_;
}
void set(const std::string& logger_name, level::level_enum lvl) level::level_enum get()
{ {
if (logger_name.empty()) return default_level_;
{ }
default_level_ = lvl;
}
else
{
levels_[logger_name] = lvl;
}
}
level::level_enum get(const std::string &logger_name) private:
{ std::unordered_map<std::string, spdlog::level::level_enum> levels_;
auto it = levels_.find(logger_name); spdlog::level::level_enum default_level_ = level::info;
return it != levels_.end() ? it->second : default_level_; };
} } // namespace cfg
level::level_enum get()
{
return default_level_;
}
private:
std::unordered_map<std::string, spdlog::level::level_enum> levels_;
spdlog::level::level_enum default_level_ = level::info;
};
} // namespace cfg
} // namespace spdlog } // namespace spdlog

View File

@ -95,7 +95,6 @@ inline log_levels extract_levels_(const std::string &input)
level = level::info; level = level::info;
} }
rv.set(logger_name, level); rv.set(logger_name, level);
} }
return rv; return rv;
} }

View File

@ -30,7 +30,6 @@
namespace spdlog { namespace spdlog {
namespace details { namespace details {
SPDLOG_INLINE registry::registry() SPDLOG_INLINE registry::registry()
: formatter_(new pattern_formatter()) : formatter_(new pattern_formatter())
{ {

View File

@ -28,7 +28,6 @@ class periodic_worker;
class registry class registry
{ {
public: public:
registry(const registry &) = delete; registry(const registry &) = delete;
registry &operator=(const registry &) = delete; registry &operator=(const registry &) = delete;