laravel在終端中查看日志的方法


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 里面加上

  1. Event::listen('illuminate.query', function($query, $bindings, $time, $name)
  2. {
  3. $data = compact('bindings', 'time', 'name');
  4.  
  5. // Format binding data for sql insertion
  6. foreach ($bindings as $i => $binding)
  7. {
  8. if ($binding instanceof \DateTime)
  9. {
  10. $bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
  11. }
  12. else if (is_string($binding))
  13. {
  14. $bindings[$i] = "'$binding'";
  15. }
  16. }
  17.  
  18. // Insert bindings into query
  19. $query = str_replace(array('%', '?'), array('%%', '%s'), $query);
  20. $query = vsprintf($query, $bindings);
  21.  
  22. Log::info($query, $data);
  23. });

生產環境下的 Log

接下來我們做些配置, 查看生產環境下的 Log .

修改app/config/remote.php 文件

  1. 'connections' => array(
  2. 'production' => array(
  3. 'host' => '117.111.111.111', //
  4. 'username' => 'root',
  5. 'password' => '',
  6. 'key' => '/Users/username/.ssh/id_rsa',
  7. 'keyphrase' => '',
  8. 'root' => '/var/webroot',
  9. ),
  10. ),

服務器驗證可以選擇 用戶名密碼 方式, 也可以設置 Key.

配置完成后調用:

php artisan tail production --path=/var/www/omapi/app/storage/logs/fpm-fcgi-2014-12-12.log --env=local

就可以實時查看 Log 輸出了:

file

查看支持的參數

php artisan help tail


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM