diff options
author | Kenny Katzgrau <ext.kkatzgrau@hexiscyber.com> | 2015-03-05 15:31:55 -0500 |
---|---|---|
committer | Kenny Katzgrau <ext.kkatzgrau@hexiscyber.com> | 2015-03-05 15:31:55 -0500 |
commit | 42461f1c7c7e286a9cd0d9aa1fc7b2d269f932c0 (patch) | |
tree | ceb372039ab898aa8e237aa6bd1263e8dfa55266 | |
parent | fba7bf2ce2fd957904ebf26122fa2acfb4b28217 (diff) | |
download | KLogger-42461f1c7c7e286a9cd0d9aa1fc7b2d269f932c0.zip KLogger-42461f1c7c7e286a9cd0d9aa1fc7b2d269f932c0.tar.gz KLogger-42461f1c7c7e286a9cd0d9aa1fc7b2d269f932c0.tar.bz2 |
Add filename option
-rw-r--r-- | README.markdown | 5 | ||||
-rwxr-xr-x | src/Logger.php | 14 |
2 files changed, 14 insertions, 5 deletions
diff --git a/README.markdown b/README.markdown index 00dfce4..3acf7cd 100644 --- a/README.markdown +++ b/README.markdown @@ -130,10 +130,11 @@ Here's the full list: | Option | Default | Description | | ------ | ------- | ----------- | -| extension | 'txt' | The log file extension | -| prefix | 'log_' | The log file prefix | | dateFormat | 'Y-m-d G:i:s.u' | The format of the date in the start of the log lone (php formatted) | +| extension | 'txt' | The log file extension | +| filename | [prefix][date].[extension] | Set the filename for the log file. **This overrides the prefix and extention options.** | | flushFrequency | `false` (disabled) | How many lines to flush the output buffer after | +| prefix | 'log_' | The log file prefix | ## Why use KLogger? diff --git a/src/Logger.php b/src/Logger.php index a563724..c56bfaf 100755 --- a/src/Logger.php +++ b/src/Logger.php @@ -38,10 +38,11 @@ class Logger extends AbstractLogger * @var array
*/
private $options = array (
- 'prefix' => 'log_',
'extension' => 'txt',
'dateFormat' => 'Y-m-d G:i:s.u',
- 'flushFrequency' => false
+ 'filename' => false,
+ 'flushFrequency' => false,
+ 'prefix' => 'log_'
);
/**
@@ -115,7 +116,14 @@ class Logger extends AbstractLogger mkdir($logDirectory, $this->defaultPermissions, true);
}
- $this->logFilePath = $logDirectory.DIRECTORY_SEPARATOR.$this->options['prefix'].date('Y-m-d').'.'.$this->options['extension'];
+ // Check for a set filename. In that case ignore prefix and 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.');
}
|