laravel5.7 日志代码执行顺序问题

想看看laravel是怎样对monolog进行封装的,然后就点开了代码。问题就来了,大伙帮忙看下:

控制器代码

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class JustForTest extends Controller
{
    //
    public function index()
    {
        // dd(get_class_methods('Log'));
        // 记录日志
        Log::info('test', ['msg' => 'just for the test']);

        return view('test', ['data' => 'test']);
    }
}

点开Log


namespace Illuminate\Support\Facades;

class Log extends Facade
{
    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return 'log';
    }
}

点开Facade

<?php

namespace Illuminate\Support\Facades;

use Mockery;
use RuntimeException;
use Mockery\MockInterface;

abstract class Facade
{
    /**
     * Handle dynamic, static calls to the object.
     *
     * @param  string  $method
     * @param  array   $args
     * @return mixed
     *
     * @throws \RuntimeException
     */
    public static function __callStatic($method, $args)
    {
        $instance = static::getFacadeRoot();

        dd($instance);

        if (! $instance) {
            throw new RuntimeException('A facade root has not been set.');
        }

        return $instance->$method(...$args);
    }
}

尽管这里终止了代码,日志照样还是可以生成,说明并没有走这里,这时候我就找不到问题在哪里了,请教下大伙。非常感谢

阅读 2.4k
1 个回答

Facade在Laravel中属于一个很重要的概念。

轻描淡写是不太容易讲清楚,简单归纳就是 '静态代理' 使用静态方法调用实例化的对象。至于详细内容可以参阅Laravel的文档。

如果只是为了查看 Logs 中的实现 可以在安装 Laravel-idee-helper 后直接点击。function 名 定位到 vendor 中的源码进行查阅。

XDebug 调试通过了这里,Laravel 版本 5.5.*。

clipboard.png

  • 调用代码

clipboard.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题