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