From 303b943d60fa69b2caa4acc838ff145dd10bc4c5 Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Tue, 22 Oct 2019 07:58:20 -0700 Subject: [PATCH 1/5] Fix Logger config --- app/Config/Logger.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/app/Config/Logger.php b/app/Config/Logger.php index d32e195fe3c6..b98e772004e1 100644 --- a/app/Config/Logger.php +++ b/app/Config/Logger.php @@ -38,9 +38,8 @@ class Logger extends BaseConfig |-------------------------------------------------------------------------- | Error Logging Directory Path |-------------------------------------------------------------------------- - | - | - | + | By default, logs are written to WRITEPATH . 'logs/' + | Specify a different destination here, if desired. */ public $path = ''; @@ -102,19 +101,13 @@ class Logger extends BaseConfig ], /* - * Leave this BLANK unless you would like to set something other than the default - * writeable/logs/ directory. Use a full getServer path with trailing slash. - */ - 'path' => WRITEPATH . 'logs/', - - /* - * The default filename extension for log files. The default 'php' allows for - * protecting the log files via basic scripting, when they are to be stored - * under a publicly accessible directory. + * The default filename extension for log files. + * An extension of 'php' allows for protecting the log files via basic + * scripting, when they are to be stored under a publicly accessible directory. * * Note: Leaving it blank will default to 'php'. */ - 'fileExtension' => 'php', + 'fileExtension' => 'log', /* * The file system permissions to be applied on newly created log files. From c420bf51b8dcbaf1ab74d5effbc7056ee4ad8f58 Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Tue, 22 Oct 2019 08:28:42 -0700 Subject: [PATCH 2/5] Fix Logger config --- app/Config/Logger.php | 4 ++-- system/Log/Handlers/FileHandler.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Config/Logger.php b/app/Config/Logger.php index b98e772004e1..64e4aa1929a2 100644 --- a/app/Config/Logger.php +++ b/app/Config/Logger.php @@ -105,9 +105,9 @@ class Logger extends BaseConfig * An extension of 'php' allows for protecting the log files via basic * scripting, when they are to be stored under a publicly accessible directory. * - * Note: Leaving it blank will default to 'php'. + * Note: Leaving it blank will default to 'log'. */ - 'fileExtension' => 'log', + 'fileExtension' => '', /* * The file system permissions to be applied on newly created log files. diff --git a/system/Log/Handlers/FileHandler.php b/system/Log/Handlers/FileHandler.php index d83750ebb988..f9598c5746f7 100644 --- a/system/Log/Handlers/FileHandler.php +++ b/system/Log/Handlers/FileHandler.php @@ -79,7 +79,7 @@ public function __construct(array $config = []) $this->path = $config['path'] ?? WRITEPATH . 'logs/'; - $this->fileExtension = $config['fileExtension'] ?? 'php'; + $this->fileExtension = $config['fileExtension'] ?? 'log'; $this->fileExtension = ltrim($this->fileExtension, '.'); $this->filePermissions = $config['filePermissions'] ?? 0644; From 31eaa2a2c2ab372ee9f67d9f2bee1e662c5b2a27 Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Tue, 22 Oct 2019 12:42:40 -0700 Subject: [PATCH 3/5] Fix Logger default extension --- tests/system/Log/FileHandlerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/Log/FileHandlerTest.php b/tests/system/Log/FileHandlerTest.php index 24b07d4fc468..d0007f70813c 100644 --- a/tests/system/Log/FileHandlerTest.php +++ b/tests/system/Log/FileHandlerTest.php @@ -46,7 +46,7 @@ public function testHandleCreateFile() $logger->setDateFormat('Y-m-d H:i:s:u'); $logger->handle('warning', 'This is a test log'); - $expected = 'log-' . date('Y-m-d') . '.php'; + $expected = 'log-' . date('Y-m-d') . '.log'; $fp = fopen($config->path . $expected, 'r'); $line = fgets($fp); fclose($fp); @@ -63,7 +63,7 @@ public function testHandleDateTimeCorrectly() $logger = new MockFileHandler((array) $config); $logger->setDateFormat('Y-m-d'); - $expected = 'log-' . date('Y-m-d') . '.php'; + $expected = 'log-' . date('Y-m-d') . '.log'; $logger->handle('debug', 'Test message'); From 7c0b0cecba094e29659eb37b84058456b4b0df43 Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Tue, 22 Oct 2019 13:28:34 -0700 Subject: [PATCH 4/5] Expected message changed --- tests/system/Log/FileHandlerTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/system/Log/FileHandlerTest.php b/tests/system/Log/FileHandlerTest.php index d0007f70813c..2a49eb3dd946 100644 --- a/tests/system/Log/FileHandlerTest.php +++ b/tests/system/Log/FileHandlerTest.php @@ -52,8 +52,8 @@ public function testHandleCreateFile() fclose($fp); // did the log file get created? - $expectedResult = "\n"; - $this->assertEquals($expectedResult, $line); + $expectedResult = 'This is a test log'; + $this->assertContains($expectedResult, $line); } public function testHandleDateTimeCorrectly() @@ -73,8 +73,8 @@ public function testHandleDateTimeCorrectly() $line = fgets($fp); // and get the second line fclose($fp); - $expectedResult = 'DEBUG - ' . date('Y-m-d') . ' --> Test message'; - $this->assertEquals($expectedResult, substr($line, 0, strlen($expectedResult))); + $expectedResult = 'Test message'; + $this->assertContains($expectedResult, $line); } } From b89c735ce1955cf061a1d3cb15221f21944ad7a2 Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Tue, 22 Oct 2019 14:07:39 -0700 Subject: [PATCH 5/5] Fix unit test --- tests/system/Log/FileHandlerTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/system/Log/FileHandlerTest.php b/tests/system/Log/FileHandlerTest.php index 2a49eb3dd946..2a4ba94cf6d3 100644 --- a/tests/system/Log/FileHandlerTest.php +++ b/tests/system/Log/FileHandlerTest.php @@ -66,10 +66,7 @@ public function testHandleDateTimeCorrectly() $expected = 'log-' . date('Y-m-d') . '.log'; $logger->handle('debug', 'Test message'); - $fp = fopen($config->path . $expected, 'r'); - $line = fgets($fp); // skip opening PHP tag - $line = fgets($fp); // skip blank line $line = fgets($fp); // and get the second line fclose($fp);