@@ -90,7 +90,7 @@ LogBufferManager::preproc_buffers(LogBufferSink *sink)
9090
9191LogObject::LogObject (const LogFormat *format, const char *log_dir, const char *basename, LogFileFormat file_format,
9292 const char *header, Log::RollingEnabledValues rolling_enabled, int flush_threads, int rolling_interval_sec,
93- int rolling_offset_hr, int rolling_size_mb, bool auto_created)
93+ int rolling_offset_hr, int rolling_size_mb, bool auto_created, int max_rolled, bool reopen_after_rolling )
9494 : m_alt_filename(nullptr ),
9595 m_flags(0 ),
9696 m_signature(0 ),
@@ -99,6 +99,8 @@ LogObject::LogObject(const LogFormat *format, const char *log_dir, const char *b
9999 m_rolling_offset_hr(rolling_offset_hr),
100100 m_rolling_size_mb(rolling_size_mb),
101101 m_last_roll_time(0 ),
102+ m_max_rolled(max_rolled),
103+ m_reopen_after_rolling(reopen_after_rolling),
102104 m_buffer_manager_idx(0 )
103105{
104106 ink_release_assert (format);
@@ -118,6 +120,10 @@ LogObject::LogObject(const LogFormat *format, const char *log_dir, const char *b
118120
119121 m_logFile = new LogFile (m_filename, header, file_format, m_signature, Log::config->ascii_buffer_size , Log::config->max_line_size );
120122
123+ if (m_reopen_after_rolling) {
124+ m_logFile->open_file ();
125+ }
126+
121127 LogBuffer *b = new LogBuffer (this , Log::config->log_buffer_size );
122128 ink_assert (b);
123129 SET_FREELIST_POINTER_VERSION (m_log_buffer, b, 0 );
@@ -140,14 +146,19 @@ LogObject::LogObject(LogObject &rhs)
140146 m_rolling_offset_hr(rhs.m_rolling_offset_hr),
141147 m_rolling_size_mb(rhs.m_rolling_size_mb),
142148 m_last_roll_time(rhs.m_last_roll_time),
149+ m_max_rolled(rhs.m_max_rolled),
150+ m_reopen_after_rolling(rhs.m_reopen_after_rolling),
143151 m_buffer_manager_idx(rhs.m_buffer_manager_idx)
144-
145152{
146153 m_format = new LogFormat (*(rhs.m_format ));
147154 m_buffer_manager = new LogBufferManager[m_flush_threads];
148155
149156 if (rhs.m_logFile ) {
150157 m_logFile = new LogFile (*(rhs.m_logFile ));
158+
159+ if (m_reopen_after_rolling) {
160+ m_logFile->open_file ();
161+ }
151162 } else {
152163 m_logFile = nullptr ;
153164 }
@@ -746,7 +757,11 @@ LogObject::_roll_files(long last_roll_time, long time_now)
746757 if (m_logFile) {
747758 // no need to roll if object writes to a pipe
748759 if (!writes_to_pipe ()) {
749- num_rolled += m_logFile->roll (last_roll_time, time_now);
760+ num_rolled += m_logFile->roll (last_roll_time, time_now, m_reopen_after_rolling);
761+
762+ if (Log::config->auto_delete_rolled_files && m_max_rolled > 0 ) {
763+ m_logFile->trim_rolled (m_max_rolled);
764+ }
750765 }
751766 }
752767
@@ -770,9 +785,9 @@ const LogFormat *TextLogObject::textfmt = MakeTextLogFormat();
770785
771786TextLogObject::TextLogObject (const char *name, const char *log_dir, bool timestamps, const char *header,
772787 Log::RollingEnabledValues rolling_enabled, int flush_threads, int rolling_interval_sec,
773- int rolling_offset_hr, int rolling_size_mb)
788+ int rolling_offset_hr, int rolling_size_mb, int max_rolled, bool reopen_after_rolling )
774789 : LogObject(TextLogObject::textfmt, log_dir, name, LOG_FILE_ASCII, header, rolling_enabled, flush_threads, rolling_interval_sec,
775- rolling_offset_hr, rolling_size_mb)
790+ rolling_offset_hr, rolling_size_mb, max_rolled, reopen_after_rolling )
776791{
777792 if (timestamps) {
778793 this ->set_fmt_timestamps ();
0 commit comments