Browse Source

Merge pull request #16994 from cakephp/log-deprecation

5.0 - Add deprecation for logging config change
Mark Story 3 years ago
parent
commit
73d2aaee23
2 changed files with 26 additions and 6 deletions
  1. 5 6
      src/Log/Engine/BaseLog.php
  2. 21 0
      tests/TestCase/Log/LogTest.php

+ 5 - 6
src/Log/Engine/BaseLog.php

@@ -20,7 +20,6 @@ use ArrayObject;
 use Cake\Core\InstanceConfigTrait;
 use Cake\Log\Formatter\AbstractFormatter;
 use Cake\Log\Formatter\DefaultFormatter;
-use InvalidArgumentException;
 use JsonSerializable;
 use Psr\Log\AbstractLogger;
 use Serializable;
@@ -58,11 +57,11 @@ abstract class BaseLog extends AbstractLogger
     {
         $this->setConfig($config);
 
-        assert(
-            $this->_config['scopes'] !== false,
-            new InvalidArgumentException('Use `null` instead of `false` to disable scopes.')
-        );
-
+        // 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'];
         }

+ 21 - 0
tests/TestCase/Log/LogTest.php

@@ -397,6 +397,27 @@ class LogTest extends TestCase
     }
 
     /**
+     * Test scoped logging backwards compat
+     */
+    public function testScopedLoggingBackwardsCompat(): void
+    {
+        $this->_deleteLogs();
+
+        Log::setConfig('debug', [
+            'engine' => 'File',
+            'path' => LOGS,
+            'levels' => ['notice', 'info', 'debug'],
+            'file' => 'debug',
+            'scopes' => false,
+        ]);
+
+        $this->deprecated(function () {
+            Log::write('debug', 'debug message', 'orders');
+        });
+        $this->assertFileDoesNotExist(LOGS . 'debug.log');
+    }
+
+    /**
      * Test scoped logging without the default loggers catching everything
      */
     public function testScopedLoggingStrict(): void