From cd995db43dfb5cc954c7e7457fb3d89fc9c8950a Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 9 Dec 2024 23:51:32 +0530 Subject: [PATCH 01/14] Bump dep versions for split packages --- composer.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 468980829..b4dce7ae6 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,8 @@ "source": "https://github.com/cakephp/log" }, "require": { - "php": ">=8.1", - "cakephp/core": "^5.1", + "php": ">=8.4", + "cakephp/core": "6.x-dev", "psr/log": "^3.0" }, "provide": { @@ -34,5 +34,7 @@ "psr-4": { "Cake\\Log\\": "." } - } + }, + "minimum-stability": "dev", + "prefer-stable": true } From 050ba9fd4903c355ff9ab6a856d0f9404e7c2853 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 27 Dec 2024 17:57:53 +0530 Subject: [PATCH 02/14] Remove deprecated code. --- Engine/BaseLog.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Engine/BaseLog.php b/Engine/BaseLog.php index 13eb95043..56e19d20f 100644 --- a/Engine/BaseLog.php +++ b/Engine/BaseLog.php @@ -24,7 +24,6 @@ use Psr\Log\AbstractLogger; use Serializable; use Stringable; -use function Cake\Core\deprecationWarning; /** * Base log engine class. @@ -58,11 +57,6 @@ public function __construct(array $config = []) { $this->setConfig($config); - // Backwards compatibility shim as we can't deprecate using false because of how 4.x merges configuration. - if ($this->_config['scopes'] === false) { - deprecationWarning('5.0.0', 'Using `false` to disable logging scopes is deprecated. Use `null` instead.'); - $this->_config['scopes'] = null; - } if ($this->_config['scopes'] !== null) { $this->_config['scopes'] = (array)$this->_config['scopes']; } From f0e4dbb055b942537187eb24e2923ae48162b187 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 2 Feb 2025 21:26:11 +0530 Subject: [PATCH 03/14] Add `static` return type. --- LogEngineRegistry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LogEngineRegistry.php b/LogEngineRegistry.php index 570badf42..d773519d2 100644 --- a/LogEngineRegistry.php +++ b/LogEngineRegistry.php @@ -87,7 +87,7 @@ protected function _create(callable|object|string $class, string $alias, array $ * @param string $name The logger name. * @return $this */ - public function unload(string $name) + public function unload(string $name): static { unset($this->_loaded[$name]); From 7bcb86fa52387c0c80c69827d1903700173f467b Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sat, 31 May 2025 11:16:00 +0200 Subject: [PATCH 04/14] 6.x remove underscore from methods (#18687) * remove underscores from collection package methods via rector * remove underscores from command package methods via rector * remove underscores from console package methods via rector * remove underscores from controller package methods via rector * remove underscores from core package methods via rector * remove underscores from database package methods via rector * remove underscores from datasource package methods via rector * remove underscores from error package methods via rector * remove underscores from event package methods via rector * remove underscores from form package methods via rector * remove underscores from http package methods via rector * remove underscores from I18N package methods via rector * remove underscores from Log package methods via rector * remove underscores from mailer package methods via rector * remove underscores from network package methods via rector * remove underscores from orm package methods via rector * remove underscores from routing package methods via rector * remove underscores from testsuite package methods via rector * remove underscores from utility package methods via rector * remove underscores from validation package methods via rector * remove underscores from view package methods via rector * fix phpstan --- Engine/FileLog.php | 8 ++++---- Engine/SyslogLog.php | 8 ++++---- LogEngineRegistry.php | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Engine/FileLog.php b/Engine/FileLog.php index 662df1eb6..004857623 100644 --- a/Engine/FileLog.php +++ b/Engine/FileLog.php @@ -126,9 +126,9 @@ public function log($level, Stringable|string $message, array $context = []): vo $message = $this->interpolate($message, $context); $message = $this->formatter->format($level, $message, $context); - $filename = $this->_getFilename($level); + $filename = $this->getFilename($level); if ($this->_size) { - $this->_rotateFile($filename); + $this->rotateFile($filename); } $pathname = $this->_path . $filename; @@ -159,7 +159,7 @@ public function log($level, Stringable|string $message, array $context = []): vo * @param string $level The level of log. * @return string File name */ - protected function _getFilename(string $level): string + protected function getFilename(string $level): string { $debugTypes = ['notice', 'info', 'debug']; @@ -184,7 +184,7 @@ protected function _getFilename(string $level): string * @return bool|null True if rotated successfully or false in case of error. * Null if file doesn't need to be rotated. */ - protected function _rotateFile(string $filename): ?bool + protected function rotateFile(string $filename): ?bool { $filePath = $this->_path . $filename; clearstatcache(true, $filePath); diff --git a/Engine/SyslogLog.php b/Engine/SyslogLog.php index f940cdbc7..a2312f716 100644 --- a/Engine/SyslogLog.php +++ b/Engine/SyslogLog.php @@ -103,7 +103,7 @@ public function log($level, Stringable|string $message, array $context = []): vo { if (!$this->_open) { $config = $this->_config; - $this->_open($config['prefix'], $config['flag'], $config['facility']); + $this->open($config['prefix'], $config['flag'], $config['facility']); $this->_open = true; } @@ -114,7 +114,7 @@ public function log($level, Stringable|string $message, array $context = []): vo $lines = explode("\n", $this->interpolate($message, $context)); foreach ($lines as $line) { - $this->_write($priority, $this->formatter->format($level, $line, $context)); + $this->write($priority, $this->formatter->format($level, $line, $context)); } } @@ -127,7 +127,7 @@ public function log($level, Stringable|string $message, array $context = []): vo * @param int $facility the stream or facility to log to * @return void */ - protected function _open(string $ident, int $options, int $facility): void + protected function open(string $ident, int $options, int $facility): void { openlog($ident, $options, $facility); } @@ -140,7 +140,7 @@ protected function _open(string $ident, int $options, int $facility): void * @param string $message Message to log. * @return bool */ - protected function _write(int $priority, string $message): bool + protected function write(int $priority, string $message): bool { return syslog($priority, $message); } diff --git a/LogEngineRegistry.php b/LogEngineRegistry.php index d773519d2..e456e7282 100644 --- a/LogEngineRegistry.php +++ b/LogEngineRegistry.php @@ -36,7 +36,7 @@ class LogEngineRegistry extends ObjectRegistry * @param string $class Partial classname to resolve. * @return class-string<\Psr\Log\LoggerInterface>|null Either the correct class name or null. */ - protected function _resolveClassName(string $class): ?string + protected function resolveClassName(string $class): ?string { /** @var class-string<\Psr\Log\LoggerInterface>|null */ return App::className($class, 'Log/Engine', 'Log'); @@ -52,7 +52,7 @@ protected function _resolveClassName(string $class): ?string * @return void * @throws \Cake\Core\Exception\CakeException */ - protected function _throwMissingClassError(string $class, ?string $plugin): void + protected function throwMissingClassError(string $class, ?string $plugin): void { throw new CakeException(sprintf('Could not load class `%s`.', $class)); } @@ -67,7 +67,7 @@ protected function _throwMissingClassError(string $class, ?string $plugin): void * @param array $config An array of settings to use for the logger. * @return \Psr\Log\LoggerInterface The constructed logger class. */ - protected function _create(callable|object|string $class, string $alias, array $config): LoggerInterface + protected function create(callable|object|string $class, string $alias, array $config): LoggerInterface { if (is_string($class)) { /** @var class-string<\Psr\Log\LoggerInterface> $class */ From ca1cf848c64b0749d3b384d9cc4603005576b814 Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 10 Sep 2025 19:38:32 +0530 Subject: [PATCH 05/14] Fix rector issues --- Formatter/DefaultFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Formatter/DefaultFormatter.php b/Formatter/DefaultFormatter.php index 75bc044f1..483662039 100644 --- a/Formatter/DefaultFormatter.php +++ b/Formatter/DefaultFormatter.php @@ -37,7 +37,7 @@ class DefaultFormatter extends AbstractFormatter public function format($level, string $message, array $context = []): string { if ($this->_config['includeDate']) { - $message = sprintf('%s %s: %s', (new DateTime())->format($this->_config['dateFormat']), $level, $message); + $message = sprintf('%s %s: %s', new DateTime()->format($this->_config['dateFormat']), $level, $message); } else { $message = sprintf('%s: %s', $level, $message); } From 6be48d8222e4b7c6cc4b8705faa38c22326f3965 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sun, 5 Oct 2025 15:37:12 +0200 Subject: [PATCH 06/14] remove underscores from cache properties --- Log.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Log.php b/Log.php index 67ddd4665..45bbc9a60 100644 --- a/Log.php +++ b/Log.php @@ -118,7 +118,7 @@ class Log * @var array * @phpstan-var array */ - protected static array $_dsnClassMap = [ + protected static array $dsnClassMap = [ 'console' => Engine\ConsoleLog::class, 'file' => Engine\FileLog::class, 'syslog' => Engine\SyslogLog::class, @@ -136,7 +136,7 @@ class Log * * @var \Cake\Log\LogEngineRegistry */ - protected static LogEngineRegistry $_registry; + protected static LogEngineRegistry $registry; /** * Handled log levels @@ -179,21 +179,21 @@ class Log */ protected static function getRegistry(): LogEngineRegistry { - static::$_registry ??= new LogEngineRegistry(); + static::$registry ??= new LogEngineRegistry(); if (static::$_dirtyConfig) { - foreach (static::$_config as $name => $properties) { + foreach (static::$config as $name => $properties) { if (isset($properties['engine'])) { $properties['className'] = $properties['engine']; } - if (!static::$_registry->has((string)$name)) { - static::$_registry->load((string)$name, $properties); + if (!static::$registry->has((string)$name)) { + static::$registry->load((string)$name, $properties); } } } static::$_dirtyConfig = false; - return static::$_registry; + return static::$registry; } /** @@ -208,10 +208,10 @@ protected static function getRegistry(): LogEngineRegistry */ public static function reset(): void { - if (isset(static::$_registry)) { - static::$_registry->reset(); + if (isset(static::$registry)) { + static::$registry->reset(); } - static::$_config = []; + static::$config = []; static::$_dirtyConfig = true; } From cb3829fec5826859d04d0a3698a58318613fdffa Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Mon, 6 Oct 2025 18:38:09 +0200 Subject: [PATCH 07/14] remove underscores from core properties --- Engine/ArrayLog.php | 2 +- Engine/BaseLog.php | 18 +++++++++--------- Engine/ConsoleLog.php | 4 ++-- Engine/FileLog.php | 20 ++++++++++---------- Engine/SyslogLog.php | 4 ++-- Formatter/AbstractFormatter.php | 2 +- Formatter/DefaultFormatter.php | 8 ++++---- Formatter/JsonFormatter.php | 8 ++++---- LogEngineRegistry.php | 2 +- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Engine/ArrayLog.php b/Engine/ArrayLog.php index ece7799e5..9618f6222 100644 --- a/Engine/ArrayLog.php +++ b/Engine/ArrayLog.php @@ -33,7 +33,7 @@ class ArrayLog extends BaseLog * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ 'levels' => [], 'scopes' => [], 'formatter' => [ diff --git a/Engine/BaseLog.php b/Engine/BaseLog.php index 0d0b6dff3..04d7f1ad4 100644 --- a/Engine/BaseLog.php +++ b/Engine/BaseLog.php @@ -37,7 +37,7 @@ abstract class BaseLog extends AbstractLogger * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ 'levels' => [], 'scopes' => [], 'formatter' => DefaultFormatter::class, @@ -57,18 +57,18 @@ public function __construct(array $config = []) { $this->setConfig($config); - if ($this->_config['scopes'] !== null) { - $this->_config['scopes'] = (array)$this->_config['scopes']; + if ($this->config['scopes'] !== null) { + $this->config['scopes'] = (array)$this->config['scopes']; } - $this->_config['levels'] = (array)$this->_config['levels']; + $this->config['levels'] = (array)$this->config['levels']; - if (!empty($this->_config['types']) && empty($this->_config['levels'])) { - $this->_config['levels'] = (array)$this->_config['types']; + if (!empty($this->config['types']) && empty($this->config['levels'])) { + $this->config['levels'] = (array)$this->config['types']; } /** @var \Cake\Log\Formatter\AbstractFormatter|array|class-string<\Cake\Log\Formatter\AbstractFormatter> $formatter */ - $formatter = $this->_config['formatter'] ?? DefaultFormatter::class; + $formatter = $this->config['formatter'] ?? DefaultFormatter::class; if (!is_object($formatter)) { if (is_array($formatter)) { /** @var class-string<\Cake\Log\Formatter\AbstractFormatter> $class */ @@ -91,7 +91,7 @@ public function __construct(array $config = []) */ public function levels(): array { - return $this->_config['levels']; + return $this->config['levels']; } /** @@ -101,7 +101,7 @@ public function levels(): array */ public function scopes(): ?array { - return $this->_config['scopes']; + return $this->config['scopes']; } /** diff --git a/Engine/ConsoleLog.php b/Engine/ConsoleLog.php index 73db8a721..f1648329e 100644 --- a/Engine/ConsoleLog.php +++ b/Engine/ConsoleLog.php @@ -31,7 +31,7 @@ class ConsoleLog extends BaseLog * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ 'stream' => 'php://stderr', 'levels' => null, 'scopes' => [], @@ -67,7 +67,7 @@ public function __construct(array $config = []) { parent::__construct($config); - $config = $this->_config; + $config = $this->config; if ($config['stream'] instanceof ConsoleOutput) { $this->_output = $config['stream']; } elseif (is_string($config['stream'])) { diff --git a/Engine/FileLog.php b/Engine/FileLog.php index 49abffea9..1be4408e1 100644 --- a/Engine/FileLog.php +++ b/Engine/FileLog.php @@ -45,7 +45,7 @@ class FileLog extends BaseLog * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ 'path' => null, 'file' => null, 'types' => null, @@ -92,21 +92,21 @@ public function __construct(array $config = []) $this->_path = $this->getConfig('path', sys_get_temp_dir() . DIRECTORY_SEPARATOR); if (!is_dir($this->_path)) { - mkdir($this->_path, $this->_config['dirMask'] ^ umask(), true); + mkdir($this->_path, $this->config['dirMask'] ^ umask(), true); } - if (!empty($this->_config['file'])) { - $this->_file = $this->_config['file']; + if (!empty($this->config['file'])) { + $this->_file = $this->config['file']; if (!str_ends_with($this->_file, '.log')) { $this->_file .= '.log'; } } - if (!empty($this->_config['size'])) { - if (is_numeric($this->_config['size'])) { - $this->_size = (int)$this->_config['size']; + if (!empty($this->config['size'])) { + if (is_numeric($this->config['size'])) { + $this->_size = (int)$this->config['size']; } else { - $this->_size = Text::parseFileSize($this->_config['size']); + $this->_size = Text::parseFileSize($this->config['size']); } } } @@ -132,7 +132,7 @@ public function log($level, Stringable|string $message, array $context = []): vo } $pathname = $this->_path . $filename; - $mask = $this->_config['mask']; + $mask = $this->config['mask']; if (!$mask) { file_put_contents($pathname, $message . "\n", FILE_APPEND); @@ -196,7 +196,7 @@ protected function rotateFile(string $filename): ?bool return null; } - $rotate = $this->_config['rotate']; + $rotate = $this->config['rotate']; if ($rotate === 0) { $result = unlink($filePath); } else { diff --git a/Engine/SyslogLog.php b/Engine/SyslogLog.php index 83b2c743f..f483750a6 100644 --- a/Engine/SyslogLog.php +++ b/Engine/SyslogLog.php @@ -51,7 +51,7 @@ class SyslogLog extends BaseLog * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ 'levels' => [], 'scopes' => [], 'flag' => LOG_ODELAY, @@ -102,7 +102,7 @@ class SyslogLog extends BaseLog public function log($level, Stringable|string $message, array $context = []): void { if (!$this->_open) { - $config = $this->_config; + $config = $this->config; $this->open($config['prefix'], $config['flag'], $config['facility']); $this->_open = true; } diff --git a/Formatter/AbstractFormatter.php b/Formatter/AbstractFormatter.php index 5629d7800..ff8049764 100644 --- a/Formatter/AbstractFormatter.php +++ b/Formatter/AbstractFormatter.php @@ -27,7 +27,7 @@ abstract class AbstractFormatter * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ ]; /** diff --git a/Formatter/DefaultFormatter.php b/Formatter/DefaultFormatter.php index 483662039..56553a027 100644 --- a/Formatter/DefaultFormatter.php +++ b/Formatter/DefaultFormatter.php @@ -25,7 +25,7 @@ class DefaultFormatter extends AbstractFormatter * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ 'dateFormat' => 'Y-m-d H:i:s', 'includeTags' => false, 'includeDate' => true, @@ -36,12 +36,12 @@ class DefaultFormatter extends AbstractFormatter */ public function format($level, string $message, array $context = []): string { - if ($this->_config['includeDate']) { - $message = sprintf('%s %s: %s', new DateTime()->format($this->_config['dateFormat']), $level, $message); + if ($this->config['includeDate']) { + $message = sprintf('%s %s: %s', new DateTime()->format($this->config['dateFormat']), $level, $message); } else { $message = sprintf('%s: %s', $level, $message); } - if ($this->_config['includeTags']) { + if ($this->config['includeTags']) { return sprintf('<%s>%s', $level, $message, $level); } diff --git a/Formatter/JsonFormatter.php b/Formatter/JsonFormatter.php index 55e322ec7..24ca85d33 100644 --- a/Formatter/JsonFormatter.php +++ b/Formatter/JsonFormatter.php @@ -23,7 +23,7 @@ class JsonFormatter extends AbstractFormatter * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ 'dateFormat' => DATE_ATOM, 'flags' => JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES, 'appendNewline' => true, @@ -34,9 +34,9 @@ class JsonFormatter extends AbstractFormatter */ public function format($level, string $message, array $context = []): string { - $log = ['date' => date($this->_config['dateFormat']), 'level' => (string)$level, 'message' => $message]; - $json = json_encode($log, JSON_THROW_ON_ERROR | $this->_config['flags']); + $log = ['date' => date($this->config['dateFormat']), 'level' => (string)$level, 'message' => $message]; + $json = json_encode($log, JSON_THROW_ON_ERROR | $this->config['flags']); - return $this->_config['appendNewline'] ? $json . "\n" : $json; + return $this->config['appendNewline'] ? $json . "\n" : $json; } } diff --git a/LogEngineRegistry.php b/LogEngineRegistry.php index e456e7282..3c25fb82d 100644 --- a/LogEngineRegistry.php +++ b/LogEngineRegistry.php @@ -89,7 +89,7 @@ protected function create(callable|object|string $class, string $alias, array $c */ public function unload(string $name): static { - unset($this->_loaded[$name]); + unset($this->loaded[$name]); return $this; } From b837a7affce6b3e455196e53a936aa0f04c53063 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sat, 17 Jan 2026 18:59:49 +0100 Subject: [PATCH 08/14] cleanup underscore properties in Log package (#19201) * cleanup underscore properties in Log package * fix rector issues * fix stan --- Engine/ConsoleLog.php | 10 +++++----- Engine/FileLog.php | 34 +++++++++++++++++----------------- Engine/SyslogLog.php | 6 +++--- Log.php | 22 +++++++++++----------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Engine/ConsoleLog.php b/Engine/ConsoleLog.php index f1648329e..16e4f6e67 100644 --- a/Engine/ConsoleLog.php +++ b/Engine/ConsoleLog.php @@ -47,7 +47,7 @@ class ConsoleLog extends BaseLog * * @var \Cake\Console\ConsoleOutput */ - protected ConsoleOutput $_output; + protected ConsoleOutput $output; /** * Constructs a new Console Logger. @@ -69,15 +69,15 @@ public function __construct(array $config = []) $config = $this->config; if ($config['stream'] instanceof ConsoleOutput) { - $this->_output = $config['stream']; + $this->output = $config['stream']; } elseif (is_string($config['stream'])) { - $this->_output = new ConsoleOutput($config['stream']); + $this->output = new ConsoleOutput($config['stream']); } else { throw new InvalidArgumentException('`stream` not a ConsoleOutput nor string'); } if (isset($config['outputAs'])) { - $this->_output->setOutputAs($config['outputAs']); + $this->output->setOutputAs($config['outputAs']); } } @@ -94,6 +94,6 @@ public function __construct(array $config = []) public function log($level, Stringable|string $message, array $context = []): void { $message = $this->interpolate($message, $context); - $this->_output->write($this->formatter->format($level, $message, $context)); + $this->output->write($this->formatter->format($level, $message, $context)); } } diff --git a/Engine/FileLog.php b/Engine/FileLog.php index 61a6b6a80..1a251be16 100644 --- a/Engine/FileLog.php +++ b/Engine/FileLog.php @@ -65,21 +65,21 @@ class FileLog extends BaseLog * * @var string */ - protected string $_path; + protected string $path; /** * The name of the file to save logs into. * * @var string|null */ - protected ?string $_file = null; + protected ?string $file = null; /** * Max file size, used for log file rotation. * * @var int|null */ - protected ?int $_size = null; + protected ?int $size = null; /** * Sets protected properties based on config provided @@ -90,23 +90,23 @@ public function __construct(array $config = []) { parent::__construct($config); - $this->_path = $this->getConfig('path', sys_get_temp_dir() . DIRECTORY_SEPARATOR); - if (!is_dir($this->_path)) { - mkdir($this->_path, $this->config['dirMask'] ^ umask(), true); + $this->path = $this->getConfig('path', sys_get_temp_dir() . DIRECTORY_SEPARATOR); + if (!is_dir($this->path)) { + mkdir($this->path, $this->config['dirMask'] ^ umask(), true); } if (!empty($this->config['file'])) { - $this->_file = $this->config['file']; - if (!str_ends_with($this->_file, '.log')) { - $this->_file .= '.log'; + $this->file = $this->config['file']; + if (!str_ends_with($this->file, '.log')) { + $this->file .= '.log'; } } if (!empty($this->config['size'])) { if (is_numeric($this->config['size'])) { - $this->_size = (int)$this->config['size']; + $this->size = (int)$this->config['size']; } else { - $this->_size = Text::parseFileSize($this->config['size']); + $this->size = Text::parseFileSize($this->config['size']); } } } @@ -127,11 +127,11 @@ public function log($level, Stringable|string $message, array $context = []): vo $message = $this->formatter->format($level, $message, $context); $filename = $this->getFilename($level); - if ($this->_size) { + if ($this->size) { $this->rotateFile($filename); } - $pathname = $this->_path . $filename; + $pathname = $this->path . $filename; $mask = $this->config['mask']; if (!$mask) { file_put_contents($pathname, $message . "\n", FILE_APPEND); @@ -163,8 +163,8 @@ protected function getFilename(string $level): string { $debugTypes = ['notice', 'info', 'debug']; - if ($this->_file) { - $filename = $this->_file; + if ($this->file) { + $filename = $this->file; } elseif ($level === 'error' || $level === 'warning') { $filename = 'error.log'; } elseif (in_array($level, $debugTypes, true)) { @@ -186,12 +186,12 @@ protected function getFilename(string $level): string */ protected function rotateFile(string $filename): ?bool { - $filePath = $this->_path . $filename; + $filePath = $this->path . $filename; clearstatcache(true, $filePath); if ( !is_file($filePath) || - filesize($filePath) < $this->_size + filesize($filePath) < $this->size ) { return null; } diff --git a/Engine/SyslogLog.php b/Engine/SyslogLog.php index f483750a6..4cb94fdd1 100644 --- a/Engine/SyslogLog.php +++ b/Engine/SyslogLog.php @@ -84,7 +84,7 @@ class SyslogLog extends BaseLog * * @var bool */ - protected bool $_open = false; + protected bool $open = false; /** * Writes a message to syslog @@ -101,10 +101,10 @@ class SyslogLog extends BaseLog */ public function log($level, Stringable|string $message, array $context = []): void { - if (!$this->_open) { + if (!$this->open) { $config = $this->config; $this->open($config['prefix'], $config['flag'], $config['facility']); - $this->_open = true; + $this->open = true; } $priority = LOG_DEBUG; diff --git a/Log.php b/Log.php index 34d655adb..0418f707c 100644 --- a/Log.php +++ b/Log.php @@ -129,7 +129,7 @@ class Log * * @var bool */ - protected static bool $_dirtyConfig = false; + protected static bool $dirtyConfig = false; /** * LogEngineRegistry class @@ -143,7 +143,7 @@ class Log * * @var array */ - protected static array $_levels = [ + protected static array $levels = [ 'emergency', 'alert', 'critical', @@ -160,7 +160,7 @@ class Log * * @var array */ - protected static array $_levelMap = [ + protected static array $levelMap = [ 'emergency' => LOG_EMERG, 'alert' => LOG_ALERT, 'critical' => LOG_CRIT, @@ -181,7 +181,7 @@ protected static function getRegistry(): LogEngineRegistry { static::$registry ??= new LogEngineRegistry(); - if (static::$_dirtyConfig) { + if (static::$dirtyConfig) { foreach (static::$config as $name => $properties) { if (isset($properties['engine'])) { $properties['className'] = $properties['engine']; @@ -191,7 +191,7 @@ protected static function getRegistry(): LogEngineRegistry } } } - static::$_dirtyConfig = false; + static::$dirtyConfig = false; return static::$registry; } @@ -212,7 +212,7 @@ public static function reset(): void static::$registry->reset(); } static::$config = []; - static::$_dirtyConfig = true; + static::$dirtyConfig = true; } /** @@ -225,7 +225,7 @@ public static function reset(): void */ public static function levels(): array { - return static::$_levels; + return static::$levels; } /** @@ -271,7 +271,7 @@ public static function levels(): array public static function setConfig(array|string $key, LoggerInterface|Closure|array|null $config = null): void { static::_setConfig($key, $config); - static::$_dirtyConfig = true; + static::$dirtyConfig = true; } /** @@ -346,11 +346,11 @@ public static function engine(string $name): ?LoggerInterface */ public static function write(string|int $level, Stringable|string $message, array|string $context = []): bool { - if (is_int($level) && in_array($level, static::$_levelMap, true)) { - $level = array_search($level, static::$_levelMap, true); + if (is_int($level) && in_array($level, static::$levelMap, true)) { + $level = array_search($level, static::$levelMap, true); } - if (!in_array($level, static::$_levels, true)) { + if (!in_array($level, static::$levels, true)) { throw new InvalidArgumentException(sprintf('Invalid log level `%s`', $level)); } From ea1d5fe433c6604824a5111ace70e963c7e75d00 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sat, 7 Feb 2026 12:33:41 +0100 Subject: [PATCH 09/14] more underscore cleanup (#19254) --- Engine/ArrayLog.php | 2 +- Engine/ConsoleLog.php | 2 +- Engine/FileLog.php | 2 +- Engine/SyslogLog.php | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Engine/ArrayLog.php b/Engine/ArrayLog.php index f9d8c14bd..7c812afcf 100644 --- a/Engine/ArrayLog.php +++ b/Engine/ArrayLog.php @@ -56,7 +56,7 @@ class ArrayLog extends BaseLog * @param \Stringable|string $message The message you want to log. * @param array $context Additional information about the logged message * @return void - * @see \Cake\Log\Log::$_levels + * @see \Cake\Log\Log::$levels * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint */ public function log($level, Stringable|string $message, array $context = []): void diff --git a/Engine/ConsoleLog.php b/Engine/ConsoleLog.php index 8d8716507..bd73ecac7 100644 --- a/Engine/ConsoleLog.php +++ b/Engine/ConsoleLog.php @@ -88,7 +88,7 @@ public function __construct(array $config = []) * @param \Stringable|string $message The message you want to log. * @param array $context Additional information about the logged message * @return void - * @see \Cake\Log\Log::$_levels + * @see \Cake\Log\Log::$levels * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint */ public function log($level, Stringable|string $message, array $context = []): void diff --git a/Engine/FileLog.php b/Engine/FileLog.php index 1a251be16..de4e9a140 100644 --- a/Engine/FileLog.php +++ b/Engine/FileLog.php @@ -118,7 +118,7 @@ public function __construct(array $config = []) * @param \Stringable|string $message The message you want to log. * @param array $context Additional information about the logged message * @return void - * @see \Cake\Log\Log::$_levels + * @see \Cake\Log\Log::$levels * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint */ public function log($level, Stringable|string $message, array $context = []): void diff --git a/Engine/SyslogLog.php b/Engine/SyslogLog.php index 4cb94fdd1..4aafa58fc 100644 --- a/Engine/SyslogLog.php +++ b/Engine/SyslogLog.php @@ -68,7 +68,7 @@ class SyslogLog extends BaseLog * * @var array */ - protected array $_levelMap = [ + protected array $levelMap = [ 'emergency' => LOG_EMERG, 'alert' => LOG_ALERT, 'critical' => LOG_CRIT, @@ -96,7 +96,7 @@ class SyslogLog extends BaseLog * @param \Stringable|string $message The message you want to log. * @param array $context Additional information about the logged message * @return void - * @see \Cake\Log\Log::$_levels + * @see \Cake\Log\Log::$levels * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint */ public function log($level, Stringable|string $message, array $context = []): void @@ -108,8 +108,8 @@ public function log($level, Stringable|string $message, array $context = []): vo } $priority = LOG_DEBUG; - if (isset($this->_levelMap[$level])) { - $priority = $this->_levelMap[$level]; + if (isset($this->levelMap[$level])) { + $priority = $this->levelMap[$level]; } $lines = explode("\n", $this->interpolate($message, $context)); From 0450ccabd0627bce63bef83c14a5f351ad2572e6 Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 12 Feb 2026 06:47:46 +0100 Subject: [PATCH 10/14] Add dsnClassMap property to StaticConfigTrait This change adds the `$dsnClassMap` property directly to StaticConfigTrait using a lazy initialization pattern via `buildDsnClassMap()`. Classes that need a custom DSN class map override `buildDsnClassMap()` instead of declaring their own property. Benefits: - Property is now defined in the trait, eliminating PHPStan issues - Implementing classes use `buildDsnClassMap()` for customization - Maintains backwards compatibility via `getDsnClassMap()`/`setDsnClassMap()` Note: The `$registry` property is NOT added to the trait because implementing classes require specific registry types (CacheRegistry, LogEngineRegistry, etc.) that cannot be generalized in the trait. Refs cakephp/cakephp#wiki/6.0-Ideas --- Log.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Log.php b/Log.php index 0a59898af..ef6c065ea 100644 --- a/Log.php +++ b/Log.php @@ -112,18 +112,6 @@ class Log setConfig as protected _setConfig; } - /** - * An array mapping url schemes to fully qualified Log engine class names - * - * @var array - * @phpstan-var array - */ - protected static array $dsnClassMap = [ - 'console' => Engine\ConsoleLog::class, - 'file' => Engine\FileLog::class, - 'syslog' => Engine\SyslogLog::class, - ]; - /** * Internal flag for tracking whether configuration has been changed. * @@ -171,6 +159,20 @@ class Log 'debug' => LOG_DEBUG, ]; + /** + * Returns the default DSN class map. + * + * @return array + */ + protected static function buildDsnClassMap(): array + { + return [ + 'console' => Engine\ConsoleLog::class, + 'file' => Engine\FileLog::class, + 'syslog' => Engine\SyslogLog::class, + ]; + } + /** * Creates registry if doesn't exist and creates all defined logging * adapters if config isn't loaded. From ce8e0a223bbc873cadb47c25139074c5dc3a2c65 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 21 Feb 2026 15:07:39 +0530 Subject: [PATCH 11/14] Rename StaticConfigTrait::buildDsnClassMap() to initDsnClassMap() --- Log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Log.php b/Log.php index ef6c065ea..076a4fe22 100644 --- a/Log.php +++ b/Log.php @@ -164,7 +164,7 @@ class Log * * @return array */ - protected static function buildDsnClassMap(): array + protected static function initDsnClassMap(): array { return [ 'console' => Engine\ConsoleLog::class, From 6ee93a9cf2e3f0681819725e5d11747194392962 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 15 Mar 2026 11:41:27 +0530 Subject: [PATCH 12/14] Fix branch aliasing --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index eaccb41f9..cf769242f 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "prefer-stable": true, "extra": { "branch-alias": { - "dev-6.x": "6.0.x-dev" + "6.x-dev": "6.0.x-dev" } } } From b64cff8f173691fdbd39540a29589e3eaabc43a2 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Mon, 13 Apr 2026 20:18:13 +0200 Subject: [PATCH 13/14] Fix CS: disallow partial use statements (#19391) Replace partial namespace references (e.g. Engine\FileEngine) with fully imported class names to satisfy SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly. --- Log.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Log.php b/Log.php index 076a4fe22..97c765c7a 100644 --- a/Log.php +++ b/Log.php @@ -17,6 +17,9 @@ use Cake\Core\StaticConfigTrait; use Cake\Log\Engine\BaseLog; +use Cake\Log\Engine\ConsoleLog; +use Cake\Log\Engine\FileLog; +use Cake\Log\Engine\SyslogLog; use Closure; use InvalidArgumentException; use Psr\Log\LoggerInterface; @@ -167,9 +170,9 @@ class Log protected static function initDsnClassMap(): array { return [ - 'console' => Engine\ConsoleLog::class, - 'file' => Engine\FileLog::class, - 'syslog' => Engine\SyslogLog::class, + 'console' => ConsoleLog::class, + 'file' => FileLog::class, + 'syslog' => SyslogLog::class, ]; } From 6be49036abd865e7df01967596f7d5ebd9897210 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Wed, 22 Jul 2026 02:26:39 +0200 Subject: [PATCH 14/14] Route internal trigger_error() calls through triggerWarning() (#19558) Route all internal trigger_error() calls through triggerWarning() Centralizes error/warning emission behind Cake\Core\triggerWarning() instead of calling the native trigger_error() directly from scattered call sites across Cache, Lock, Http, View, Log, ORM, Controller, and Error. triggerWarning() now accepts an optional error level (default E_USER_WARNING) so the two call sites that used E_USER_NOTICE keep their original severity while still going through the wrapper. Discovered along the way: Cake\Core\functions_global.php (the global-namespace triggerWarning()/deprecationWarning() aliases) is never loaded by either the main package's or the cakephp/core subpackage's composer.json "autoload.files" - existing call sites only worked because they explicitly `use function Cake\Core\ triggerWarning;`. Every new call site added here does the same. --- Engine/FileLog.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Engine/FileLog.php b/Engine/FileLog.php index de4e9a140..d68017e39 100644 --- a/Engine/FileLog.php +++ b/Engine/FileLog.php @@ -19,6 +19,7 @@ use Cake\Log\Formatter\DefaultFormatter; use Cake\Utility\Text; use Stringable; +use function Cake\Core\triggerWarning; /** * File Storage stream for Logging. Writes logs to different files @@ -145,10 +146,10 @@ public function log($level, Stringable|string $message, array $context = []): vo if (!$selfError && !$exists && !chmod($pathname, (int)$mask)) { $selfError = true; - trigger_error(vsprintf( + triggerWarning(vsprintf( 'Could not apply permission mask `%s` on log file `%s`', [$mask, $pathname], - ), E_USER_WARNING); + )); $selfError = false; } }