diff options
author | onno-vos-dev <onno.vos.dev@gmail.com> | 2015-04-11 16:01:07 +0200 |
---|---|---|
committer | onno-vos-dev <onno.vos.dev@gmail.com> | 2015-04-11 16:14:48 +0200 |
commit | 9c2c45dfc4e1594d386e9d6ff5f1be948cf8f10e (patch) | |
tree | 26c6baee989aa865f4fd76e3a5692a816f643c5e | |
parent | 44f84d8c0c998a23a288d0462dc2ca55cfe0c425 (diff) | |
download | KLogger-9c2c45dfc4e1594d386e9d6ff5f1be948cf8f10e.zip KLogger-9c2c45dfc4e1594d386e9d6ff5f1be948cf8f10e.tar.gz KLogger-9c2c45dfc4e1594d386e9d6ff5f1be948cf8f10e.tar.bz2 |
Move setting of filePath to its own setter. Include a check to see if extension is provided in filename, otherwise add it
-rwxr-xr-x | src/Logger.php | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/Logger.php b/src/Logger.php index a4cd28e..17bd3bb 100755 --- a/src/Logger.php +++ b/src/Logger.php @@ -121,12 +121,7 @@ class Logger extends AbstractLogger $this->setLogToStdOut($logDirectory);
$this->setFileHandle('w+');
} else {
- if ($this->options['filename']) {
- $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'];
- } else {
- $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
- }
-
+ $this->setLogFilePath($logDirectory);
if(file_exists($this->logFilePath) && !is_writable($this->logFilePath)) {
throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
}
@@ -149,6 +144,22 @@ class Logger extends AbstractLogger }
/**
+ * @param string $logDirectory
+ */
+ public function setLogFilePath($logDirectory) {
+ if ($this->options['filename']) {
+ if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) {
+ $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'];
+ }
+ else {
+ $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'].'.'.$this->options['extension'];
+ }
+ } else {
+ $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
+ }
+ }
+
+ /**
* @param $writeMode
*
* @internal param resource $fileHandle
|