MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ScheduleNextRotation

Method ScheduleNextRotation

lib/compat/compatlogger.cpp:545–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

543}
544
545void CompatLogger::ScheduleNextRotation()
546{
547 auto now = (time_t)Utility::GetTime();
548 String method = GetRotationMethod();
549
550 tm tmthen;
551
552#ifdef _MSC_VER
553 tm *temp = localtime(&now);
554
555 if (!temp) {
556 BOOST_THROW_EXCEPTION(posix_error()
557 << boost::errinfo_api_function("localtime")
558 << boost::errinfo_errno(errno));
559 }
560
561 tmthen = *temp;
562#else /* _MSC_VER */
563 if (!localtime_r(&now, &tmthen)) {
564 BOOST_THROW_EXCEPTION(posix_error()
565 << boost::errinfo_api_function("localtime_r")
566 << boost::errinfo_errno(errno));
567 }
568#endif /* _MSC_VER */
569
570 tmthen.tm_min = 0;
571 tmthen.tm_sec = 0;
572
573 if (method == "HOURLY") {
574 tmthen.tm_hour++;
575 } else if (method == "DAILY") {
576 tmthen.tm_mday++;
577 tmthen.tm_hour = 0;
578 } else if (method == "WEEKLY") {
579 tmthen.tm_mday += 7 - tmthen.tm_wday;
580 tmthen.tm_hour = 0;
581 } else if (method == "MONTHLY") {
582 tmthen.tm_mon++;
583 tmthen.tm_mday = 1;
584 tmthen.tm_hour = 0;
585 }
586
587 time_t ts = mktime(&tmthen);
588
589 Log(LogNotice, "CompatLogger")
590 << "Rescheduling rotation timer for compat log '"
591 << GetName() << "' to '" << Utility::FormatDateTime("%Y/%m/%d %H:%M:%S %z", ts) << "'";
592
593 m_RotationTimer->Reschedule(ts);
594}
595
596/**
597 * @threadsafety Always.

Callers

nothing calls this directly

Calls 3

posix_errorClass · 0.85
LogClass · 0.85
RescheduleMethod · 0.80

Tested by

no test coverage detected