spdlog/include/c11log/sinks/base_sink.h

45 lines
878 B
C
Raw Normal View History

2014-01-25 17:09:04 +08:00
#pragma once
2014-01-25 21:52:10 +08:00
2014-01-25 17:09:04 +08:00
#include<string>
2014-01-26 07:53:23 +08:00
#include<atomic>
2014-01-25 17:09:04 +08:00
#include "../formatters/formatters.h"
#include "../level.h"
namespace c11log {
namespace sinks {
class base_sink {
public:
2014-01-26 07:53:23 +08:00
base_sink() = default;
2014-01-25 17:09:04 +08:00
base_sink(level::level_enum l):_level(l)
{};
2014-01-25 21:52:10 +08:00
virtual ~base_sink() = default;
2014-01-26 07:53:23 +08:00
2014-01-25 17:09:04 +08:00
base_sink(const base_sink&) = delete;
base_sink& operator=(const base_sink&) = delete;
void log(const std::string &msg, level::level_enum level)
{
if (level >= _level) {
2014-01-26 07:53:23 +08:00
sink_it_(msg);
2014-01-25 17:09:04 +08:00
}
};
void set_level(level::level_enum level)
{
_level = level;
}
protected:
2014-01-25 21:52:10 +08:00
virtual void sink_it_(const std::string& msg) = 0;
2014-01-27 17:44:10 +08:00
std::atomic<int> _level{level::INFO};
2014-01-25 17:09:04 +08:00
};
class null_sink:public base_sink {
protected:
2014-01-25 21:52:10 +08:00
void sink_it_(const std::string& msg) override
2014-01-25 17:09:04 +08:00
{}
};
}
2014-01-27 17:44:10 +08:00
}