因为我在理解事情时遇到了问题,所以我回来时会遇到更多的Laravel问题.
我再次尝试创建一个包来进行自己的日志记录.在做了一些额外的阅读并完成核心代码并尝试其他方法之后,我得出的结论是,我需要做的就是扩展laravel日志记录的核心功能,以便它记录到一个不同的路径自定义格式化程序
我已经创建了我的包.这是我的服务提供者类:
use Illuminate\Log\LogServiceProvider;
class VmlogServiceProvider extends LogServiceProvider {
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
App::bind('log', function()
{
return new Vm\Vmlog\Vmlog;
});
parent::boot();
}
}
?>
这是VmLog类
path = VM_LOGPATH.APP_VLCODE."/".APP_VLCODE."_".APP_INSTANCE.".log";
$this->formatter = new LineFormatter($output, $dateFormat);
parent::__construct();
}
/**
* Register a file log handler.
*
* @param string $path
* @param string $level
* @return void
*/
public function useFiles($path, $level = 'debug')
{
$level = $this->parseLevel($level);
$this->stream = new StreamHandler($this->path, $level);
$this->stream->setFormatter($this->formatter);
$this->monolog->pushHandler($this->stream);
}
/**
* Register a daily file log handler.
*
* @param string $path
* @param int $days
* @param string $level
* @return void
*/
public function useDailyFiles($path, $days = 0, $level = 'debug')
{
$level = $this->parseLevel($level);
$this->rotatingStream = new RotatingFileHandler($this->path, $days, $level);
$this->rotatingStream->setFormatter($this->formatter);
$this->monolog->pushHandler($this->rotatingStream);
}
}
?>
我在app.php中注释掉了LogServiceProvider,并在我的VmlogServiceProvider中添加了它.
然而,当我尝试运行时,我收到以下错误.
调用未定义的方法Illuminate\Support\Facades\Log :: useDailyFiles()
我不明白为什么会这样.我已经删除了核心LogServiceProvider,我已经添加了我自己的地方并按照文档(我认为)正确绑定了它.我在这做错了什么?