php将tail实时输出到页面,使用 `PHP artisan tail` 来实时查看 Laravel 应用程序的 Log...

本文介绍了如何利用php artisan tail命令在开发和生产环境中查看PHP应用的实时日志,特别是在生产环境下用于问题排查。通过在app/filters.php中添加监听器来记录SQL查询,并配置远程.php文件以连接到生产服务器的日志文件,实现远程日志监控。此外,还提到了命令行参数的使用以及如何配置SSH密钥或用户名密码进行身份验证。
摘要由CSDN通过智能技术生成

说明

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 输出了:

2cb4d87c6c23780e29d02cc930e8add2.png

查看支持的参数

php artisan help tail

摈弃世俗浮躁,追求技术精湛

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值