spdlog/include/c11log/sinks/base_sink.h

43 lines
863 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
2014-02-22 07:16:59 +08:00
#include "../formatter.h"
2014-03-01 20:06:58 +08:00
#include "../common_types.h"
2014-01-25 17:09:04 +08:00
namespace c11log {
namespace sinks {
class base_sink {
public:
2014-01-26 07:53:23 +08:00
base_sink() = default;
2014-02-22 04:51:54 +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;
2014-02-22 04:51:54 +08:00
void log(const std::string &msg, level::level_enum level) {
2014-01-25 17:09:04 +08:00
if (level >= _level) {
2014-02-22 16:34:42 +08:00
_sink_it(msg);
2014-01-25 17:09:04 +08:00
}
};
2014-02-22 04:51:54 +08:00
void set_level(level::level_enum level) {
2014-01-25 17:09:04 +08:00
_level = level;
}
protected:
2014-02-22 16:34:42 +08:00
virtual void _sink_it(const std::string& msg) = 0;
2014-02-22 04:51:54 +08:00
std::atomic<int> _level {level::INFO};
2014-01-25 17:09:04 +08:00
};
class null_sink:public base_sink {
protected:
2014-02-22 16:34:42 +08:00
void _sink_it(const std::string& ) override {
2014-02-22 04:51:54 +08:00
}
2014-01-25 17:09:04 +08:00
};
}
2014-01-27 17:44:10 +08:00
}