N°2820 Log rotation : new MonthlyRotatingLogFileNameBuilder class

This commit is contained in:
Pierre Goiffon
2020-03-02 15:52:59 +01:00
parent 2be16f9078
commit 56ef6feadf
2 changed files with 72 additions and 4 deletions

View File

@@ -331,6 +331,58 @@ class WeeklyRotatingLogFileNameBuilder extends RotatingLogFileNameBuilder
}
}
/**
* @since 2.7.0 N°2820
*/
class MonthlyRotatingLogFileNameBuilder extends RotatingLogFileNameBuilder
{
/**
* @inheritDoc
*/
public function ShouldRotate($oLogFileLastModified, $oNow)
{
$iLogYear = $oLogFileLastModified->format('Y');
$iLogMonth = $oLogFileLastModified->format('n');
$iNowYear = $oNow->format('Y');
$iNowMonth = $oNow->format('n');
if ($iLogYear !== $iNowYear)
{
return true;
}
if ($iLogMonth !== $iNowMonth)
{
return true;
}
return false;
}
/**
* @inheritDoc
*/
protected function GetFileSuffix($oDate)
{
$sWeekYear = $oDate->format('o');
$sWeekNumber = $oDate->format('m');
return $sWeekYear.'-month'.$sWeekNumber;
}
/**
* @inheritDoc
*/
public function GetCronProcessNextOccurrence(DateTime $oNow)
{
$oOccurrence = clone $oNow;
$oOccurrence->modify('first day of next month');
$oOccurrence->setTime(0, 0, 0);
return $oOccurrence;
}
}
/**
* @since 2.7.0 N°2518
*/