laravel在終端中檢視日誌的方法
阿新 • • 發佈:2019-02-07
php artisan tail --path=/Users/henryj/workspace_php/makerlab/app/storage/logs/laravel-2015-04-22.log 在mac book終端中執行的指令
原文網址:https://phphub.org/topics/291
使用 `php artisan tail` 來實時檢視 Laravel 應用程式的 Log
說明
php
artisan tail
命令可用來檢視實時的程式執行 log, 在 debug 模式關閉的情況下 ( 如: 生產環境 ), 尤其有用.
使用
開發使用
預設情況下 tail 只是針對本地的程式碼
php artisan tail
開發的時候, 還可以開啟 SQL 查詢語句的 LOG, 配合 php
artisan tail
一起使用, 對 SQL 進行監控和調優.
在 app/filters.php
裡面加上
Event::listen('illuminate.query', function($query, $bindings, $time, $name)
{
$data = compact('bindings', 'time', 'name');
// Format binding data for sql insertion
foreach ($bindings as $i => $binding)
{
if ($binding instanceof \DateTime)
{
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
}
else if (is_string($binding))
{
$bindings[$i] = "'$binding'";
}
}
// Insert bindings into query
$query = str_replace(array('%', '?'), array('%%', '%s'), $query);
$query = vsprintf($query, $bindings);
Log::info($query, $data);
});
生產環境下的 Log
接下來我們做些配置, 檢視生產環境下的 Log .
修改app/config/remote.php
檔案
'connections' => array(
'production' => array(
'host' => '117.111.111.111', //
'username' => 'root',
'password' => '',
'key' => '/Users/username/.ssh/id_rsa',
'keyphrase' => '',
'root' => '/var/webroot',
),
),
伺服器驗證可以選擇 使用者名稱密碼 方式, 也可以設定 Key.
配置完成後呼叫:
php artisan tail production --path=/var/www/omapi/app/storage/logs/fpm-fcgi-2014-12-12.log --env=local
就可以實時檢視 Log 輸出了:
檢視支援的引數
php artisan help tail