Laravel给生产环境添加监听事件(SQL日志监听)
来源:诚信在线    发布时间:2017-07-01 15:08:32

  ],

  * @param QueryExecuted $event

  */

  namespace App\Providers;

  }

  use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;

  use Illuminate\Contracts\Queue\ShouldQueue;

  *

  光有一个空的监听器是不敷的,咱们需求本身完成若何把 $sql 记载到日记外。为此,对于 QueryListener 举行改革,完美其 handle 要领以下:

  'App\Events\SomeEvent' => [

  use Log;

  /**

  {

  ];

  总结

  {

  /**

  //

  */

  Log::info($log);

  'App\Listeners\EventListener',

  //

  namespace App\Listeners;

  'App\Listeners\QueryListener',

  $sql = str_replace("?", "'%s'", $event->sql);

  protected $listen = [

  两、注册变乱

  Log::info($log);

  }

  $sql = str_replace("?", "'%s'", $event->sql);

  or

  'App\Listeners\QueryListener',

  {

  */

  'Illuminate\Database\Events\QueryExecuted' => [

  class QueryListener

  publicfunctionboot(DispatcherContract$events)

  * Register any other events for your application.

  3、增添逻辑

  use Illuminate\Queue\InteractsWithQueue;

  publicfunctionhandle(QueryExecuted$event)

  /**

  */

  laravel版本:5.2.*

  以上便是这篇文章的全部内容了,但愿本文的内容对于人人的进修或事情能带来必然的接济,假如有疑难人人能够留言交换,感谢大师对于剧本之野的撑持。

  * @param \Illuminate\Contracts\Events\Dispatcher $events

  $log = vsprintf($sql, $event->bindings);

  本文次要给各人先容的是对于Laravel给消费情况增添监听变乱(SQL日记监听)的相关内容,分享进去求人人参考进修,上面去一同看看细致的引见:

  关上 app/Listeners/QueryListener.php

  sudo /usr/local/bin/php artisan make:listener QueryListener --event=Illuminate\\Database\\Events\\QueryExecuted

  php artisan make:listener QueryListener --event=Illuminate\\Database\\Events\\QueryExecuted

  protected$listen=[

  use Illuminate\Database\Events\QueryExecuted;

  * @return void

  ];

  ],

  * The event listener mappings for the application.

  终究代码以下

  }

  * @return void

  会主动天生文件 app/Listeners/QueryListener.php

  *

  /**

  {

  use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

  * @var array

  * Handle the event.

  关上 app/Providers/EventServiceProvider.php,正在 $listen 外增添 Illuminate\Database\Events\QueryExecuted 变乱的监听器为 QueryListener

  $log = vsprintf($sql, $event->bindings);

  parent::boot($events);

  1、创立监听器

  ],

  * Create the event listener.

  }

  * @return void

  publicfunction__construct()

  }

  *

  终极代码以下

  'Illuminate\Database\Events\QueryExecuted'=>[

  *

  class EventServiceProvider extends ServiceProvider

  {


诚信在线 除注明原创以外,其余均来自互联网以及微信朋友圈,如有侵权请联系站长立即删除!
文章地址:http://www.my517517.com/ZB/20170701379.html



上一篇:详解yii2使用多个数据库的案例 下一篇:AspNet 音频文件上传和播放代码