mirror of https://github.com/gabime/spdlog.git
console sinks
parent
c9dd1169f2
commit
6cc426d0e5
@ -0,0 +1,46 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <mutex>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "base_sink.h"
|
||||||
|
|
||||||
|
namespace c11log
|
||||||
|
{
|
||||||
|
namespace sinks
|
||||||
|
{
|
||||||
|
class console_sink: public base_sink
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit console_sink(std::ostream& os):_ostream(os) {}
|
||||||
|
console_sink(const console_sink&) = delete;
|
||||||
|
console_sink& operator=(const console_sink&) = delete;
|
||||||
|
virtual ~console_sink() = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void _sink_it(const std::string& msg) override {
|
||||||
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
|
_ostream << msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& _ostream;
|
||||||
|
std::mutex _mutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,34 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <mutex>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "base_sink.h"
|
|
||||||
|
|
||||||
namespace c11log
|
|
||||||
{
|
|
||||||
namespace sinks
|
|
||||||
{
|
|
||||||
class ostream_sink: public base_sink
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit ostream_sink(std::ostream& os):_ostream(os) {}
|
|
||||||
ostream_sink(const ostream_sink&) = delete;
|
|
||||||
ostream_sink& operator=(const ostream_sink&) = delete;
|
|
||||||
virtual ~ostream_sink() = default;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void _sink_it(const std::string& msg) override {
|
|
||||||
std::lock_guard<std::mutex> lock(_mutex);
|
|
||||||
_ostream << msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream& _ostream;
|
|
||||||
std::mutex _mutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue