MCPcopy Create free account
hub / github.com/apache/trafficserver / roll

Method roll

src/proxy/logging/LogFile.cc:360–389  ·  view source on GitHub ↗

------------------------------------------------------------------------- * LogFile::roll * This function is called by a LogObject to roll its files. * * Return 1 if file rolled, 0 otherwise -------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

358 * Return 1 if file rolled, 0 otherwise
359-------------------------------------------------------------------------*/
360int
361LogFile::roll(long interval_start, long interval_end, bool reopen_after_rolling)
362{
363 if (m_log) {
364 // Due to commit 346b419 the BaseLogFile::close_file() is no longer called within BaseLogFile::roll().
365 // For diagnostic log files, the rolling is implemented by renaming and destroying the BaseLogFile object
366 // and then creating a new BaseLogFile object with the original filename. Due to possible race conditions
367 // the old/new object swap happens within lock/unlock calls within Diags.cc.
368 // For logging log files, the rolling is implemented by renaming the original file and closing it.
369 // Afterwards, the LogFile object will re-open a new file with the original file name using the original object.
370 // There is no need to protect against contention since the open/close/writes are all executed under a
371 // single log flush thread.
372 // Since these two methods of using BaseLogFile are not compatible, we perform the logging log file specific
373 // close file operation here within the containing LogFile object.
374 if (m_log->roll(interval_start, interval_end)) {
375 if (m_log->close_file()) {
376 Error("Error closing LogFile %s: %s.", m_log->get_name(), strerror(errno));
377 }
378
379 if (reopen_after_rolling) {
380 /* If we re-open now log file will be created even if there is nothing being logged */
381 m_log->open_file();
382 }
383
384 return 1;
385 }
386 }
387
388 return 0;
389}
390
391/*-------------------------------------------------------------------------
392 LogFile::reopen_if_moved

Callers 2

_roll_filesMethod · 0.45

Calls 4

ErrorClass · 0.50
close_fileMethod · 0.45
get_nameMethod · 0.45
open_fileMethod · 0.45

Tested by

no test coverage detected