Files
spdlog/include/c11log/sinks/stdout_sinks.h

35 lines
634 B
C
Raw Normal View History

2014-01-25 15:52:10 +02:00
#pragma once
2014-01-25 11:09:04 +02:00
#include <iostream>
2014-03-05 00:31:13 +02:00
#include <mutex>
#include <memory>
2014-01-25 11:09:04 +02:00
#include "base_sink.h"
2014-03-07 00:52:50 +02:00
namespace c11log
{
namespace sinks
{
class ostream_sink: public base_sink
{
2014-01-25 15:52:10 +02:00
public:
2014-03-05 00:31:13 +02:00
explicit ostream_sink(std::ostream& os):_ostream(os) {}
2014-03-07 00:52:50 +02:00
ostream_sink(const ostream_sink&) = delete;
ostream_sink& operator=(const ostream_sink&) = delete;
2014-01-25 15:52:10 +02:00
virtual ~ostream_sink() = default;
2014-01-25 11:09:04 +02:00
2014-01-25 15:52:10 +02:00
protected:
2014-02-22 10:34:42 +02:00
virtual void _sink_it(const std::string& msg) override {
2014-03-07 00:52:50 +02:00
std::lock_guard<std::mutex> lock(_mutex);
2014-02-21 22:51:54 +02:00
_ostream << msg;
}
2014-01-25 11:09:04 +02:00
2014-02-21 22:51:54 +02:00
std::ostream& _ostream;
2014-03-07 00:52:50 +02:00
std::mutex _mutex;
2014-01-25 15:52:10 +02:00
};
2014-01-25 11:09:04 +02:00
2014-02-21 22:51:54 +02:00
2014-03-05 00:31:13 +02:00
}
2014-01-25 15:52:10 +02:00
}