Skip to content

Commit

Permalink
修正未指定base path问题
Browse files Browse the repository at this point in the history
  • Loading branch information
anoxia committed Dec 19, 2018
1 parent 43c8c4c commit bea81c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/Adapter/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ class Stream extends Adapter
*/
protected $_logExt = '.log';

/**
* @var string
*/
protected $_basePath;

/**
* Stream constructor.
*
* @param string $name
* @param null|array $options
* @throws Exception
*/
public function __construct($name = '', $options = null)
public function __construct($basePath, $name = '', $options = null)
{
$mode = 'ab';

Expand All @@ -78,7 +83,15 @@ public function __construct($name = '', $options = null)
$this->_split = false;
}

$this->_mode = $mode;
if (empty($basePath)) {
throw new Exception('Base path is required');
}
if (!is_dir($basePath)) {
throw new Exception("'{$basePath}' is not exists");
}

$this->_basePath = trim($basePath, '/');
$this->_mode = $mode;
}

/**
Expand Down Expand Up @@ -130,7 +143,8 @@ public function getStream()
*/
protected function createStream($name, $model)
{
$stream = fopen($name, $model);
$file = $this->_basePath . '/' . $name;
$stream = fopen($file, $model);
if (!$stream) {
throw new Exception("Can't open stream '" . $this->_name . "'");
}
Expand Down
1 change: 0 additions & 1 deletion src/Formatter/Json.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Bee\Logger\Formatter;

use Bee\Logger\Exception;
use Phalcon\Logger\Formatter;
use Bee\Logger\Processor\ProcessIdProcessor;

Expand Down

0 comments on commit bea81c0

Please sign in to comment.