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