|
|
@ -26,6 +26,7 @@ class LogDirectoryHandler extends StreamHandler {
|
|
|
|
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
|
|
|
|
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
|
|
|
|
* @param int|null $filePermission Optional file permissions (default (0644) are only for owner read/write)
|
|
|
|
* @param int|null $filePermission Optional file permissions (default (0644) are only for owner read/write)
|
|
|
|
* @param bool $useLocking Try to lock log file before doing any writes
|
|
|
|
* @param bool $useLocking Try to lock log file before doing any writes
|
|
|
|
|
|
|
|
* @param string|null $filenamePrefix The filename prefix
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @throws Throwable If an error occurs
|
|
|
|
* @throws Throwable If an error occurs
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -35,13 +36,14 @@ class LogDirectoryHandler extends StreamHandler {
|
|
|
|
int $historyNumberOfDays = 30,
|
|
|
|
int $historyNumberOfDays = 30,
|
|
|
|
bool $bubble = true,
|
|
|
|
bool $bubble = true,
|
|
|
|
?int $filePermission = null,
|
|
|
|
?int $filePermission = null,
|
|
|
|
bool $useLocking = false
|
|
|
|
bool $useLocking = false,
|
|
|
|
|
|
|
|
?string $filenamePrefix = null
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
$dirPath = $dirPath . DIRECTORY_SEPARATOR;
|
|
|
|
$dirPath = $dirPath . DIRECTORY_SEPARATOR;
|
|
|
|
$this->normalizeDirectory($dirPath, $historyNumberOfDays);
|
|
|
|
$this->normalizeDirectory($dirPath, $filenamePrefix, $historyNumberOfDays);
|
|
|
|
|
|
|
|
|
|
|
|
parent::__construct(
|
|
|
|
parent::__construct(
|
|
|
|
$dirPath . date('Y-m-d') . '.log',
|
|
|
|
$dirPath . ($filenamePrefix ?? '') . date('Y-m-d') . '.log',
|
|
|
|
$level,
|
|
|
|
$level,
|
|
|
|
$bubble,
|
|
|
|
$bubble,
|
|
|
|
$filePermission,
|
|
|
|
$filePermission,
|
|
|
@ -54,13 +56,14 @@ class LogDirectoryHandler extends StreamHandler {
|
|
|
|
* Normalize a directory: create if missing and clear old files
|
|
|
|
* Normalize a directory: create if missing and clear old files
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $dirPath The directory path
|
|
|
|
* @param string $dirPath The directory path
|
|
|
|
|
|
|
|
* @param string|null $filenamePrefix The filename prefix
|
|
|
|
* @param int $historyNumberOfDays The maximum number of history files to keep (in number of days)
|
|
|
|
* @param int $historyNumberOfDays The maximum number of history files to keep (in number of days)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @throws Throwable If an error occurs
|
|
|
|
* @throws Throwable If an error occurs
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function normalizeDirectory (string $dirPath, int $historyNumberOfDays = 30): void {
|
|
|
|
protected final function normalizeDirectory (string $dirPath, ?string $filenamePrefix, int $historyNumberOfDays = 30): void {
|
|
|
|
if (!file_exists($dirPath) || !is_dir($dirPath)) {
|
|
|
|
if (!file_exists($dirPath) || !is_dir($dirPath)) {
|
|
|
|
error_clear_last();
|
|
|
|
error_clear_last();
|
|
|
|
if (!mkdir($dirPath, 0755, true)) {
|
|
|
|
if (!mkdir($dirPath, 0755, true)) {
|
|
|
@ -78,7 +81,13 @@ class LogDirectoryHandler extends StreamHandler {
|
|
|
|
if (!$fileInfo->isFile()) {
|
|
|
|
if (!$fileInfo->isFile()) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (preg_match('/^(?<date>\\d{4}-\\d{2}-\\d{2})(?:[_-].*)?\.log$/i', $fileInfo->getFilename(), $match) !== 1) {
|
|
|
|
if (
|
|
|
|
|
|
|
|
preg_match(
|
|
|
|
|
|
|
|
'/^' . preg_quote($filenamePrefix ?? '', '/') . '(?<date>\\d{4}-\\d{2}-\\d{2})(?:[_-].*)?\.log$/i',
|
|
|
|
|
|
|
|
$fileInfo->getFilename(),
|
|
|
|
|
|
|
|
$match
|
|
|
|
|
|
|
|
) !== 1
|
|
|
|
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|