diff --git a/.gitignore b/.gitignore index 35b4f82..80cfecd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /.DS_Store /vendor /composer.lock +/.settings/ diff --git a/src/Sofort/SofortLib/FileLogger.php b/src/Sofort/SofortLib/FileLogger.php index cfdcd9d..1e71527 100644 --- a/src/Sofort/SofortLib/FileLogger.php +++ b/src/Sofort/SofortLib/FileLogger.php @@ -61,9 +61,11 @@ public function __construct($path = '') { $srcDir = dirname(dirname(dirname(__FILE__))); - $this->_logfilePath = ($path != '') ? $path : $srcDir . '/logs/log.txt'; - $this->_errorLogfilePath = $srcDir . '/logs/error_log.txt'; - $this->_warningsLogfilePath = $srcDir . '/logs/warning_log.txt'; + $path = rtrim(rtrim($path, '/'),'\\'); + if ($path == '') { + $path = $srcDir.'/logs'; + } + $this->setLogfilePath($path); } @@ -88,7 +90,10 @@ public function log($message, $log = 'log') */ public function setLogfilePath($path) { - $this->_logfilePath = $path; + $path = rtrim(rtrim($path, '/'),'\\'); + $this->_logfilePath = $path . '/log.txt'; + $this->_errorLogfilePath = $path . '/error_log.txt'; + $this->_warningsLogfilePath = $path . '/warning_log.txt'; } @@ -170,4 +175,4 @@ protected function _logRotate() return false; } -} \ No newline at end of file +} diff --git a/tests/unit/FileLoggerTest.php b/tests/unit/FileLoggerTest.php index c23c06e..28ba851 100644 --- a/tests/unit/FileLoggerTest.php +++ b/tests/unit/FileLoggerTest.php @@ -67,9 +67,9 @@ public function testLogWriting() public function testSetLogfilePath() { $SofortLibLogger = new FileLogger('wusel'); - $this->assertAttributeEquals('wusel', '_logfilePath', $SofortLibLogger); + $this->assertAttributeEquals('wusel/log.txt', '_logfilePath', $SofortLibLogger); $SofortLibLogger->setLogfilePath('test'); - $this->assertAttributeEquals('test', '_logfilePath', $SofortLibLogger); + $this->assertAttributeEquals('test/log.txt', '_logfilePath', $SofortLibLogger); } } \ No newline at end of file