Merge pull request #265 from sbrkopac/master

Added the ability to truncate the basic file logger.
This commit is contained in:
Gabi Melman 2016-08-23 00:00:49 +03:00 committed by GitHub
commit 42dfa1975a
3 changed files with 9 additions and 8 deletions

View File

@ -36,14 +36,14 @@ inline void spdlog::drop(const std::string &name)
}
// Create multi/single threaded simple file logger
inline std::shared_ptr<spdlog::logger> spdlog::basic_logger_mt(const std::string& logger_name, const filename_t& filename, bool force_flush)
inline std::shared_ptr<spdlog::logger> spdlog::basic_logger_mt(const std::string& logger_name, const filename_t& filename, bool force_flush, bool truncate)
{
return create<spdlog::sinks::simple_file_sink_mt>(logger_name, filename, force_flush);
return create<spdlog::sinks::simple_file_sink_mt>(logger_name, filename, force_flush, truncate);
}
inline std::shared_ptr<spdlog::logger> spdlog::basic_logger_st(const std::string& logger_name, const filename_t& filename, bool force_flush)
inline std::shared_ptr<spdlog::logger> spdlog::basic_logger_st(const std::string& logger_name, const filename_t& filename, bool force_flush, bool truncate)
{
return create<spdlog::sinks::simple_file_sink_st>(logger_name, filename, force_flush);
return create<spdlog::sinks::simple_file_sink_st>(logger_name, filename, force_flush, truncate);
}
// Create multi/single threaded rotating file logger

View File

@ -30,10 +30,11 @@ class simple_file_sink : public base_sink < Mutex >
{
public:
explicit simple_file_sink(const filename_t &filename,
bool force_flush = false) :
bool force_flush = false,
bool truncate = false) :
_file_helper(force_flush)
{
_file_helper.open(filename);
_file_helper.open(filename, truncate);
}
void flush() override
{

View File

@ -71,8 +71,8 @@ void set_sync_mode();
//
// Create and register multi/single basic file logger
//
std::shared_ptr<logger> basic_logger_mt(const std::string& logger_name, const filename_t& filename,bool force_flush = false);
std::shared_ptr<logger> basic_logger_st(const std::string& logger_name, const filename_t& filename, bool force_flush = false);
std::shared_ptr<logger> basic_logger_mt(const std::string& logger_name, const filename_t& filename,bool force_flush = false, bool truncate = false);
std::shared_ptr<logger> basic_logger_st(const std::string& logger_name, const filename_t& filename, bool force_flush = false, bool truncate = false);
//
// Create and register multi/single threaded rotating file logger