Skip to content

Commit 0a0994d

Browse files
committed
Improves the File processor initialization
1 parent d6d10d2 commit 0a0994d

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

Processors/File.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Koded\Logging\Processors;
44

5-
use Exception;
65
use Koded\Exceptions\KodedException;
76

87
/**
@@ -42,19 +41,18 @@ public function __construct(array $settings)
4241
}
4342

4443
/**
45-
* NOTE: This method should be refactored at some point in time!
46-
* AVOID INIT METHODS AND CONSTRUCTORS THAT IMPLEMENTS LOGIC!
44+
* Prepares the directory and the log filename.
4745
*
4846
* @param array $settings
4947
*
50-
* @throws Exception
48+
* @throws FileProcessorException
5149
*/
5250
protected function initialize(array $settings)
5351
{
52+
umask(umask() | 0002);
53+
5454
$cwd = pathinfo($_SERVER['SCRIPT_FILENAME'] ?? '/tmp', PATHINFO_DIRNAME);
55-
$dir = rtrim(
56-
$settings['dir'] ?? $cwd . DIRECTORY_SEPARATOR . 'logs', DIRECTORY_SEPARATOR
57-
) . DIRECTORY_SEPARATOR;
55+
$dir = rtrim($settings['dir'] ?? $cwd . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
5856

5957
if (!is_dir($dir)) {
6058
throw new FileProcessorException(self::E_DIRECTORY_DOES_NOT_EXIST, [':dir' => $dir]);
@@ -66,12 +64,10 @@ protected function initialize(array $settings)
6664

6765
$dir = sprintf('%s%s%s', $dir, date('Y/m'), DIRECTORY_SEPARATOR);
6866

69-
if (!is_dir($dir)) {
70-
if (false === @mkdir($dir, 0777, true)) {
71-
// @codeCoverageIgnoreStart
72-
throw new FileProcessorException(self::E_DIRECTORY_NOT_CREATED, [':dir' => $dir]);
73-
// @codeCoverageIgnoreEnd
74-
}
67+
if (!is_dir($dir) and false === mkdir($dir, 0775, true)) {
68+
// @codeCoverageIgnoreStart
69+
throw new FileProcessorException(self::E_DIRECTORY_NOT_CREATED, [':dir' => $dir]);
70+
// @codeCoverageIgnoreEnd
7571
}
7672

7773
$this->filename = sprintf('%s%s%s', $dir, date('d'), $settings['extension'] ?? '.log');

0 commit comments

Comments
 (0)