Skip to content

Commit e0b8cb1

Browse files
committed
Merge pull request #33 from ziadoz/patch-4
Added file extension option to logger.
2 parents 1d7121c + 58ee718 commit e0b8cb1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Log/DateTimeFileWriter.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class DateTimeFileWriter
6868
* name_format:
6969
* (string) The log file name format; parsed with `date()`.
7070
*
71+
* extension:
72+
* (string) The file extention to append to the filename`.
73+
*
7174
* message_format:
7275
* (string) The log message format; available tokens are...
7376
* %label% Replaced with the log message level (e.g. FATAL, ERROR, WARN).
@@ -83,6 +86,7 @@ public function __construct($settings = array())
8386
$this->settings = array_merge(array(
8487
'path' => './logs',
8588
'name_format' => 'Y-m-d',
89+
'extension' => 'log',
8690
'message_format' => '%label% - %date% - %message%'
8791
), $settings);
8892

@@ -129,7 +133,12 @@ public function write($object, $level)
129133

130134
//Open resource handle to log file
131135
if (!$this->resource) {
132-
$this->resource = fopen($this->settings['path'] . DIRECTORY_SEPARATOR . date($this->settings['name_format']), 'a');
136+
$filename = date($this->settings['name_format']);
137+
if (! empty($this->settings['extension'])) {
138+
$filename .= '.' . $this->settings['extension'];
139+
}
140+
141+
$this->resource = fopen($this->settings['path'] . DIRECTORY_SEPARATOR . $filename, 'a');
133142
}
134143

135144
//Output to resource

0 commit comments

Comments
 (0)