mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 10:31:34 +08:00
Merge pull request #265 from sbrkopac/master
Added the ability to truncate the basic file logger.
This commit is contained in:
commit
42dfa1975a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user