Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Logger config #2358

Merged
merged 5 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}