Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
spdlog::sinks::daily_file_sink< Mutex, FileNameCalc > Class Template Referencefinal

#include <daily_file_sink.h>

Inheritance diagram for spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >:
spdlog::sinks::base_sink< Mutex > spdlog::sinks::sink

Public Member Functions

 daily_file_sink (filename_t base_filename, int rotation_hour, int rotation_minute, bool truncate=false)
 
- Public Member Functions inherited from spdlog::sinks::base_sink< Mutex >
 base_sink ()=default
 
 base_sink (const base_sink &)=delete
 
base_sinkoperator= (const base_sink &)=delete
 
void log (const details::log_msg &msg) final
 
void flush () final
 
void set_pattern (const std::string &pattern) final
 
void set_formatter (std::unique_ptr< spdlog::formatter > sink_formatter) final
 
- Public Member Functions inherited from spdlog::sinks::sink
 sink ()
 
 sink (std::unique_ptr< spdlog::pattern_formatter > formatter)
 
virtual ~sink ()=default
 
bool should_log (level::level_enum msg_level) const
 
void set_level (level::level_enum log_level)
 
level::level_enum level () const
 

Protected Member Functions

void sink_it_ (const details::log_msg &msg) override
 
void flush_ () override
 
- Protected Member Functions inherited from spdlog::sinks::base_sink< Mutex >
virtual void set_pattern_ (const std::string &pattern)
 
virtual void set_formatter_ (std::unique_ptr< spdlog::formatter > sink_formatter)
 

Private Member Functions

tm now_tm (log_clock::time_point tp)
 
log_clock::time_point next_rotation_tp_ ()
 

Private Attributes

filename_t base_filename_
 
int rotation_h_
 
int rotation_m_
 
log_clock::time_point rotation_tp_
 
details::file_helper file_helper_
 
bool truncate_
 

Additional Inherited Members

- Protected Attributes inherited from spdlog::sinks::base_sink< Mutex >
Mutex mutex_
 
- Protected Attributes inherited from spdlog::sinks::sink
level_t level_
 
std::unique_ptr< spdlog::formatterformatter_
 

Detailed Description

template<typename Mutex, typename FileNameCalc = daily_filename_calculator>
class spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >

Definition at line 47 of file daily_file_sink.h.

Constructor & Destructor Documentation

template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::daily_file_sink ( filename_t  base_filename,
int  rotation_hour,
int  rotation_minute,
bool  truncate = false 
)
inline

Definition at line 51 of file daily_file_sink.h.

52  : base_filename_(std::move(base_filename))
53  , rotation_h_(rotation_hour)
54  , rotation_m_(rotation_minute)
55  , truncate_(truncate)
56  {
57  if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59)
58  {
59  throw spdlog_ex("daily_file_sink: Invalid rotation time in ctor");
60  }
61  auto now = log_clock::now();
62  file_helper_.open(FileNameCalc::calc_filename(base_filename_, now_tm(now)), truncate_);
64  }
log_clock::time_point rotation_tp_
void open(const filename_t &fname, bool truncate=false)
Definition: file_helper.h:42
log_clock::time_point next_rotation_tp_()
tm now_tm(log_clock::time_point tp)
details::file_helper file_helper_
def move(depos, offset)
Definition: depos.py:107

Member Function Documentation

template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
void spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::flush_ ( )
inlineoverrideprotectedvirtual

Implements spdlog::sinks::base_sink< Mutex >.

Definition at line 80 of file daily_file_sink.h.

81  {
83  }
details::file_helper file_helper_
template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
log_clock::time_point spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::next_rotation_tp_ ( )
inlineprivate

Definition at line 92 of file daily_file_sink.h.

93  {
94  auto now = log_clock::now();
95  tm date = now_tm(now);
96  date.tm_hour = rotation_h_;
97  date.tm_min = rotation_m_;
98  date.tm_sec = 0;
99  auto rotation_time = log_clock::from_time_t(std::mktime(&date));
100  if (rotation_time > now)
101  {
102  return rotation_time;
103  }
104  return {rotation_time + std::chrono::hours(24)};
105  }
tm now_tm(log_clock::time_point tp)
template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
tm spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::now_tm ( log_clock::time_point  tp)
inlineprivate

Definition at line 86 of file daily_file_sink.h.

87  {
88  time_t tnow = log_clock::to_time_t(tp);
89  return spdlog::details::os::localtime(tnow);
90  }
std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT
Definition: os.h:73
template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
void spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::sink_it_ ( const details::log_msg msg)
inlineoverrideprotectedvirtual

Implements spdlog::sinks::base_sink< Mutex >.

Definition at line 67 of file daily_file_sink.h.

68  {
69 
70  if (msg.time >= rotation_tp_)
71  {
72  file_helper_.open(FileNameCalc::calc_filename(base_filename_, now_tm(msg.time)), truncate_);
74  }
75  fmt::memory_buffer formatted;
76  sink::formatter_->format(msg, formatted);
77  file_helper_.write(formatted);
78  }
log_clock::time_point rotation_tp_
basic_memory_buffer< char > memory_buffer
Definition: format.h:553
void msg(const char *fmt,...)
Definition: message.cpp:107
void open(const filename_t &fname, bool truncate=false)
Definition: file_helper.h:42
std::unique_ptr< spdlog::formatter > formatter_
Definition: sink.h:55
log_clock::time_point next_rotation_tp_()
tm now_tm(log_clock::time_point tp)
details::file_helper file_helper_
void write(const fmt::memory_buffer &buf)
Definition: file_helper.h:83

Member Data Documentation

template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
filename_t spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::base_filename_
private

Definition at line 107 of file daily_file_sink.h.

template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
details::file_helper spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::file_helper_
private

Definition at line 111 of file daily_file_sink.h.

template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
int spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::rotation_h_
private

Definition at line 108 of file daily_file_sink.h.

template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
int spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::rotation_m_
private

Definition at line 109 of file daily_file_sink.h.

template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
log_clock::time_point spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::rotation_tp_
private

Definition at line 110 of file daily_file_sink.h.

template<typename Mutex , typename FileNameCalc = daily_filename_calculator>
bool spdlog::sinks::daily_file_sink< Mutex, FileNameCalc >::truncate_
private

Definition at line 112 of file daily_file_sink.h.


The documentation for this class was generated from the following file: