Commit 6cc426d0 authored by gabime's avatar gabime

console sinks

parent c9dd1169
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "c11log/logger.h" #include "c11log/logger.h"
#include "c11log/sinks/async_sink.h" #include "c11log/sinks/async_sink.h"
#include "c11log/sinks/file_sinks.h" #include "c11log/sinks/file_sinks.h"
#include "c11log/sinks/stdout_sinks.h" #include "c11log/sinks/console_sinks.h"
#include "utils.h" #include "utils.h"
...@@ -58,9 +58,12 @@ int main(int argc, char* argv[]) ...@@ -58,9 +58,12 @@ int main(int argc, char* argv[])
auto &my_logger = get_logger("example"); auto &my_logger = get_logger("example");
auto null_sink = std::make_shared<sinks::null_sink>(); auto null_sink = std::make_shared<sinks::null_sink>();
//auto async = std::make_shared<sinks::async_sink>(1000); //auto async = std::make_shared<sinks::async_sink>(1000);
my_logger.add_sink(fsink); //my_logger.add_sink(fsink);
//my_logger.add_sink(null_sink); my_logger.add_sink(null_sink);
auto &cout_logger = get_logger("cout");
cout_logger.add_sink(sinks::stdout_sink());
cout_logger.info() << "Hello cout logger!";
auto start = system_clock::now(); auto start = system_clock::now();
......
...@@ -10,13 +10,13 @@ namespace c11log ...@@ -10,13 +10,13 @@ namespace c11log
{ {
namespace sinks namespace sinks
{ {
class ostream_sink: public base_sink class console_sink: public base_sink
{ {
public: public:
explicit ostream_sink(std::ostream& os):_ostream(os) {} explicit console_sink(std::ostream& os):_ostream(os) {}
ostream_sink(const ostream_sink&) = delete; console_sink(const console_sink&) = delete;
ostream_sink& operator=(const ostream_sink&) = delete; console_sink& operator=(const console_sink&) = delete;
virtual ~ostream_sink() = default; virtual ~console_sink() = default;
protected: protected:
virtual void _sink_it(const std::string& msg) override { virtual void _sink_it(const std::string& msg) override {
...@@ -29,6 +29,18 @@ protected: ...@@ -29,6 +29,18 @@ protected:
}; };
inline std::shared_ptr<console_sink>& stdout_sink ()
{
static auto inst = std::make_shared<console_sink>(std::cout);
return inst;
}
inline std::shared_ptr<console_sink>& stderr_sink ()
{
static auto inst = std::make_shared<console_sink>(std::cerr);
return inst;
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment