laravel在终端中查看日志的方法
2018-07-04 14:30
543 查看
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
相关文章推荐
- laravel在终端中查看日志的方法
- SQL SERVER 查看日志大小及日志已满的处理方法 (转)
- Windows 2003系统日志查看方法及常用事件?
- 查看Laravel版本号的三种方法
- Grep查看日志的方法
- 实时查看日志文件更新的方法
- 查看spark on yarn的日志和程序状态的方法
- 查看poi日志的方法
- android studio代码混淆后,查看服务器端错误日志方法
- 【LoadRunner】查看脚本请求日志和服务器返回值方法
- Android Studio上用真机调试时,无法查看Logcat日志信息解决方法
- Linux 查看ERROR日志方法
- 查看LoadRunner脚本请求日志和服务器返回值方法
- SQL SERVER 查看日志大小及日志已满的处理方法 (转)
- 查看iis错误日志时提示找不到 freb.xsl的解决方法
- 查看终端设备接入交换机的端口方法
- logcat命令使用方法和查看android系统日志缓冲区内容的方法
- 查看MySQL的错误日志的方法
- Laravel 查看版本号方法
- Android Studio 准确查看Logcat 日志的方法