diff options
author | onno-vos-dev <onno.vos.dev@gmail.com> | 2015-03-10 16:13:37 +0100 |
---|---|---|
committer | onno-vos-dev <onno.vos.dev@gmail.com> | 2015-03-10 16:13:37 +0100 |
commit | c47fff3902ba0204bf582f5f329f4ea1fc06f7c3 (patch) | |
tree | 444037363d1b11e8acf27474279968dd6414f549 | |
parent | 53a8504c44f769657c308623f782236a370dd23b (diff) | |
download | KLogger-c47fff3902ba0204bf582f5f329f4ea1fc06f7c3.zip KLogger-c47fff3902ba0204bf582f5f329f4ea1fc06f7c3.tar.gz KLogger-c47fff3902ba0204bf582f5f329f4ea1fc06f7c3.tar.bz2 |
Add support for writing log entries to php://stdout instead of a file
-rwxr-xr-x | src/Logger.php | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/Logger.php b/src/Logger.php index f5898df..f9af376 100755 --- a/src/Logger.php +++ b/src/Logger.php @@ -117,19 +117,25 @@ class Logger extends AbstractLogger mkdir($logDirectory, $this->defaultPermissions, true);
}
- // Check for a set filename. In that case ignore prefix and extension
- if ($this->options['filename']) {
- $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['filename'];
+ if($logDirectory === "php://stdout") {
+ $this->logFilePath = $logDirectory;
+ $this->fileHandle = fopen($this->logFilePath, 'w+');
} else {
- $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
- }
-
+ 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'];
+ }
- 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.');
+ 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.');
+ }
+ $this->fileHandle = fopen($this->logFilePath, 'a');
+ if(!$this->fileHandle) {
+ throw new RuntimeException('The file could not be opened. Check permissions.');
+ }
}
- $this->fileHandle = fopen($this->logFilePath, 'a');
if ( ! $this->fileHandle) {
throw new RuntimeException('The file could not be opened. Check permissions.');
}
|