当前位置: 首页>>代码示例>>PHP>>正文


PHP Log::listen方法代码示例

本文整理汇总了PHP中Illuminate\Support\Facades\Log::listen方法的典型用法代码示例。如果您正苦于以下问题:PHP Log::listen方法的具体用法?PHP Log::listen怎么用?PHP Log::listen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Facades\Log的用法示例。


在下文中一共展示了Log::listen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: use

<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Queue;
/*
|--------------------------------------------------------------------------
| Database Logging
|--------------------------------------------------------------------------
| 1) Add "require app_path().'/errors.php';" to the end of app/start/global.php
| 2) Uncomment the "Application Error Logger" section in app/start/global.php
| 3) Migrate "create_log_table", or create the table manualy
*/
Log::listen(function ($level, $message, $context) {
    // Save the php sapi and date, because the closure needs to be serialized
    $apiName = php_sapi_name();
    $date = new \DateTime();
    Queue::push(function () use($level, $message, $context, $apiName, $date) {
        DB::insert("INSERT INTO log (php_sapi_name, level, message, context, created_at) VALUES (?, ?, ?, ?, ?)", array($apiName, $level, $message, json_encode($context), $date));
    });
});
开发者ID:noherczeg,项目名称:restext,代码行数:21,代码来源:logs.php

示例2: boot

 /**
  * Boot the service provider.
  *
  * This method is called after all other service providers have
  * been registered, meaning you have access to all other services
  * that have been registered by the framework.
  *
  * @return void
  */
 public function boot(DispatcherContract $events)
 {
     parent::boot($events);
     // Publish the database migrations
     $this->publishes([__DIR__ . '/../database/migrations' => $this->app->databasePath() . '/migrations'], 'migrations');
     $this->publishes([__DIR__ . '/../config' => config_path()], 'config');
     // Log needs a closure as a listener
     Log::listen(function ($level, $message, $context) {
         // Throw out debug messages if we are not in debug mode
         if ($level == 'debug' && \Config::get('app.debug') != true) {
             return;
         }
         // Fetch the currently logged in user
         $username = ApplogHelper::currentUserName();
         // Get the list of client IP addresses
         $clientIp = ApplogHelper::getClientIps();
         // Split the log message to see how it is formatted.
         $logdata = explode(':', $message, 6);
         if (count($logdata) == 6) {
             list($classname, $traitname, $filename, $linenumber, $functionname, $message) = $logdata;
         } else {
             list($classname, $traitname, $filename, $linenumber, $functionname, $message) = ['', '', '', '', '', $message];
         }
         // Store the log entry.
         try {
             Applog::create(['type' => $level, 'classname' => $classname, 'traitname' => $traitname, 'filename' => $filename, 'linenumber' => $linenumber, 'functionname' => $functionname, 'message' => $message, 'details' => json_encode($context), 'ipaddr' => $clientIp, 'created_by' => $username, 'updated_by' => $username]);
         } catch (\Exception $e) {
             // Do nothing
         }
     });
 }
开发者ID:delatbabel,项目名称:applog,代码行数:40,代码来源:DebugServiceProvider.php


注:本文中的Illuminate\Support\Facades\Log::listen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。