Commit 42dfa197 authored by Gabi Melman's avatar Gabi Melman Committed by GitHub

Merge pull request #265 from sbrkopac/master

Added the ability to truncate the basic file logger.
parents 332b7c0d 0be736c7
......@@ -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
......
......@@ -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
{
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment