spdlog/include/c11log/sinks/base_sink.h

45 lines
875 B
C
Raw Normal View History

2014-01-25 04:09:04 -05:00
#pragma once
2014-01-25 08:52:10 -05:00
2014-01-25 04:09:04 -05:00
#include<string>
2014-01-25 18:53:23 -05:00
#include<atomic>
2014-01-25 04:09:04 -05:00
#include "../formatters/formatters.h"
#include "../level.h"
namespace c11log {
namespace sinks {
class base_sink {
public:
2014-01-25 18:53:23 -05:00
base_sink() = default;
2014-01-25 04:09:04 -05:00
base_sink(level::level_enum l):_level(l)
{};
2014-01-25 08:52:10 -05:00
virtual ~base_sink() = default;
2014-01-25 18:53:23 -05:00
2014-01-25 04:09:04 -05: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-25 18:53:23 -05:00
sink_it_(msg);
2014-01-25 04:09:04 -05:00
}
};
void set_level(level::level_enum level)
{
_level = level;
}
protected:
2014-01-25 08:52:10 -05:00
virtual void sink_it_(const std::string& msg) = 0;
2014-01-27 04:44:10 -05:00
std::atomic<int> _level{level::INFO};
2014-01-25 04:09:04 -05:00
};
class null_sink:public base_sink {
protected:
void sink_it_(const std::string& ) override
2014-01-25 04:09:04 -05:00
{}
};
}
2014-01-27 04:44:10 -05:00
}