From 51616e7393f63e1a59b0d49934bec5a03b49dabd Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 1 Nov 2019 05:59:12 -0400 Subject: [PATCH] Set default for mergeDups option in FileLog::save() method to 0 (disabled) per processwire/processwire-issues#1019 --- wire/core/FileLog.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wire/core/FileLog.php b/wire/core/FileLog.php index 4942c7bb..34ee19cd 100644 --- a/wire/core/FileLog.php +++ b/wire/core/FileLog.php @@ -126,7 +126,8 @@ class FileLog extends Wire { * @param string $str * @param array $options options to modify behavior (Added 3.0.143) * - `allowDups` (bool): Allow duplicating same log entry in same runtime/request? (default=true) - * - `mergeDups` (int): Merge previous duplicate entries that also appear near end of file? Specify int for bytes from EOF (default=1024) + * - `mergeDups` (int): Merge previous duplicate entries that also appear near end of file? + * To enable, specify int for quantity of bytes to consider from EOF, value of 1024 or higher (default=0, disabled) * - `maxTries` (int): If log entry fails to save, maximum times to re-try (default=20) * - `maxTriesDelay` (int): Micro seconds (millionths of a second) to delay between re-tries (default=2000) * @return bool Success state: true if log written, false if not. @@ -135,7 +136,7 @@ class FileLog extends Wire { public function save($str, array $options = array()) { $defaults = array( - 'mergeDups' => 1024, + 'mergeDups' => 0, 'allowDups' => true, 'maxTries' => 20, 'maxTriesDelay' => 2000, @@ -186,7 +187,8 @@ class FileLog extends Wire { // if opened for reading and writing, merge duplicates of $line if($mode === 'r+' && $options['mergeDups']) { // do not repeat the same log entry in the same chunk - $chunkSize = is_int($options['mergeDups']) ? $options['mergeDups'] : $this->chunkSize; + $chunkSize = (int) $options['mergeDups']; + if($chunkSize < 1024) $chunkSize = 1024; fseek($fp, -1 * $chunkSize, SEEK_END); $chunk = fread($fp, $chunkSize); // check if our log line already appears in the immediate earlier chunk