vs2013 support
This commit is contained in:
		@@ -140,11 +140,14 @@ private:
 | 
			
		||||
        return system_clock::time_point(midnight + hours(24));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	//Create filename for the form basename.YYYY-MM-DD.extension
 | 
			
		||||
    static std::string _calc_filename(const std::string& basename, const std::string& extension) {
 | 
			
		||||
        std::tm tm = c11log::details::os::localtime();
 | 
			
		||||
        char buf[32];
 | 
			
		||||
        sprintf(buf, ".%d-%02d-%02d.", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
 | 
			
		||||
        return basename+buf+extension;
 | 
			
		||||
        std::tm tm = c11log::details::os::localtime();		
 | 
			
		||||
		std::ostringstream oss;
 | 
			
		||||
		oss << basename << '.';
 | 
			
		||||
		oss << tm.tm_year + 1900 << '-' << std::setw(2) << std::setfill('0') << tm.tm_mon + 1 << '-' << tm.tm_mday;
 | 
			
		||||
		oss << '.' << extension;
 | 
			
		||||
		return oss.str();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::string _base_filename;
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class stderr_sink:public ostream_sink {
 | 
			
		||||
public:
 | 
			
		||||
    stderr_sink():ostream_sink(std::cerr) {}
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
inline std::shared_ptr<ostream_sink> cout_sink() {
 | 
			
		||||
	static const ostream_sink& instance{std::cout};
 | 
			
		||||
	return std::shared_ptr<ostream_sink>(&instance, [=](ostream_sink*) {});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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*) {});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user