Skip to content

Commit

Permalink
Merge pull request #2358 from jim-parry/fix/log
Browse files Browse the repository at this point in the history
Fix Logger config
  • Loading branch information
jim-parry authored Oct 22, 2019
2 parents a1904bf + b89c735 commit ba60732
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
21 changes: 7 additions & 14 deletions app/Config/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';

Expand Down Expand Up @@ -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'.
* Note: Leaving it blank will default to 'log'.
*/
'fileExtension' => 'php',
'fileExtension' => '',

/*
* The file system permissions to be applied on newly created log files.
Expand Down
2 changes: 1 addition & 1 deletion system/Log/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 6 additions & 9 deletions tests/system/Log/FileHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ 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);

// did the log file get created?
$expectedResult = "<?php defined('SYSTEMPATH') || exit('No direct script access allowed'); ?>\n";
$this->assertEquals($expectedResult, $line);
$expectedResult = 'This is a test log';
$this->assertContains($expectedResult, $line);
}

public function testHandleDateTimeCorrectly()
Expand All @@ -63,18 +63,15 @@ 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');

$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);

$expectedResult = 'DEBUG - ' . date('Y-m-d') . ' --> Test message';
$this->assertEquals($expectedResult, substr($line, 0, strlen($expectedResult)));
$expectedResult = 'Test message';
$this->assertContains($expectedResult, $line);
}

}

0 comments on commit ba60732

Please sign in to comment.