本文整理汇总了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));
});
});
示例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
}
});
}