wip static-lib

This commit is contained in:
gabime 2019-05-12 23:36:48 +03:00
parent d5c9bac3c7
commit 26a064ed2d
4 changed files with 53 additions and 20 deletions

View File

@ -0,0 +1,39 @@
// Copyright(c) 2015-present Gabi Melman & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once
#include "spdlog/common.h"
#include "spdlog/details/os.h"
namespace spdlog {
namespace sinks {
template<typename Mutex>
SPDLOG_INLINE basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename, bool truncate)
{
file_helper_.open(filename, truncate);
}
template<typename Mutex>
SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const
{
return file_helper_.filename();
}
template<typename Mutex>
SPDLOG_INLINE void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
{
fmt::memory_buffer formatted;
sink::formatter_->format(msg, formatted);
file_helper_.write(formatted);
}
template<typename Mutex>
SPDLOG_INLINE void basic_file_sink<Mutex>::flush_()
{
file_helper_.flush();
}
} // namespace sinks
} // namespace spdlog

View File

@ -23,28 +23,12 @@ template<typename Mutex>
class basic_file_sink final : public base_sink<Mutex> class basic_file_sink final : public base_sink<Mutex>
{ {
public: public:
explicit basic_file_sink(const filename_t &filename, bool truncate = false) explicit basic_file_sink(const filename_t &filename, bool truncate = false);
{ const filename_t &filename() const;
file_helper_.open(filename, truncate);
}
const filename_t &filename() const
{
return file_helper_.filename();
}
protected: protected:
void sink_it_(const details::log_msg &msg) override void sink_it_(const details::log_msg &msg) override;
{ void flush_() override;
fmt::memory_buffer formatted;
sink::formatter_->format(msg, formatted);
file_helper_.write(formatted);
}
void flush_() override
{
file_helper_.flush();
}
private: private:
details::file_helper file_helper_; details::file_helper file_helper_;
@ -71,3 +55,7 @@ inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, c
} }
} // namespace spdlog } // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY
#include "basic_file_sink-inl.h"
#endif

View File

@ -36,6 +36,11 @@ template spdlog::logger::logger(std::string name, sinks_init_list::iterator begi
template class spdlog::sinks::base_sink<std::mutex>; template class spdlog::sinks::base_sink<std::mutex>;
template class spdlog::sinks::base_sink<spdlog::details::null_mutex>; template class spdlog::sinks::base_sink<spdlog::details::null_mutex>;
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/basic_file_sink-inl.h"
template class spdlog::sinks::basic_file_sink<std::mutex>;
template class spdlog::sinks::basic_file_sink<spdlog::details::null_mutex>;
#include "spdlog/sinks/rotating_file_sink.h" #include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/rotating_file_sink-inl.h" #include "spdlog/sinks/rotating_file_sink-inl.h"
template class spdlog::sinks::rotating_file_sink<std::mutex>; template class spdlog::sinks::rotating_file_sink<std::mutex>;

View File

@ -20,3 +20,4 @@
#include "spdlog/sinks/ostream_sink.h" #include "spdlog/sinks/ostream_sink.h"
#include "spdlog/sinks/rotating_file_sink.h" #include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/details/pattern_formatter.h"