mirror of https://github.com/gabime/spdlog.git
vs2013 support
parent
8b27eb0f01
commit
4b5364d356
@ -1,32 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
|
||||
#include "base_sink.h"
|
||||
|
||||
namespace c11log {
|
||||
namespace sinks {
|
||||
class ostream_sink: public base_sink {
|
||||
public:
|
||||
ostream_sink(std::ostream& os):_ostream(os) {}
|
||||
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;
|
||||
};
|
||||
|
||||
class stdout_sink:public ostream_sink {
|
||||
public:
|
||||
stdout_sink():ostream_sink(std::cout) {}
|
||||
};
|
||||
inline std::shared_ptr<ostream_sink> cout_sink() {
|
||||
static const ostream_sink& instance{std::cout};
|
||||
return std::shared_ptr<ostream_sink>(&instance, [=](ostream_sink*) {});
|
||||
}
|
||||
|
||||
class stderr_sink:public ostream_sink {
|
||||
public:
|
||||
stderr_sink():ostream_sink(std::cerr) {}
|
||||
inline std::shared_ptr<ostream_sink> cerr_sink() {
|
||||
static const ostream_sink& instance = ostream_sink(std::cerr);
|
||||
return std::shared_ptr<ostream_sink>(&instance, [=](ostream_sink*) {});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue