1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 08:17:12 +02:00

Set default for mergeDups option in FileLog::save() method to 0 (disabled) per processwire/processwire-issues#1019

This commit is contained in:
Ryan Cramer
2019-11-01 05:59:12 -04:00
parent 69e2c0e729
commit 51616e7393

View File

@@ -126,7 +126,8 @@ class FileLog extends Wire {
* @param string $str * @param string $str
* @param array $options options to modify behavior (Added 3.0.143) * @param array $options options to modify behavior (Added 3.0.143)
* - `allowDups` (bool): Allow duplicating same log entry in same runtime/request? (default=true) * - `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) * - `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) * - `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. * @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()) { public function save($str, array $options = array()) {
$defaults = array( $defaults = array(
'mergeDups' => 1024, 'mergeDups' => 0,
'allowDups' => true, 'allowDups' => true,
'maxTries' => 20, 'maxTries' => 20,
'maxTriesDelay' => 2000, 'maxTriesDelay' => 2000,
@@ -186,7 +187,8 @@ class FileLog extends Wire {
// if opened for reading and writing, merge duplicates of $line // if opened for reading and writing, merge duplicates of $line
if($mode === 'r+' && $options['mergeDups']) { if($mode === 'r+' && $options['mergeDups']) {
// do not repeat the same log entry in the same chunk // 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); fseek($fp, -1 * $chunkSize, SEEK_END);
$chunk = fread($fp, $chunkSize); $chunk = fread($fp, $chunkSize);
// check if our log line already appears in the immediate earlier chunk // check if our log line already appears in the immediate earlier chunk