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

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
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/113137.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号