Home > Backend Development > PHP Tutorial > How to view logs in laravel terminal

How to view logs in laravel terminal

不言
Release: 2023-04-02 14:22:02
Original
3686 people have browsed it

This article mainly introduces the method of viewing logs in the terminal of laravel. It has certain reference value. Now I share it with you. Friends in need can refer to it

php artisan tail --path=/Users/henryj/workspace_php/makerlab/app/storage/logs/laravel-2015-04-22.log Instructions to run in mac book terminal

Use `php artisan tail` to view the Log of Laravel application in real time

Instructions

php The artisan tail command can be used to view the real-time program running log. It is especially useful when the debug mode is turned off (such as a production environment).

Use

Development usage

By default tail is only for local code

php artisan tail
Copy after login

When developing, you can also open the LOG of the SQL query statement and use it with php artisan tail to monitor and control SQL Tuning.

In app/filters.php add

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);
});
Copy after login

Log in the production environment

Next let’s do something Configuration, view the Log in the production environment.

Modifyapp/config/remote.php File

'connections' => array(
'production' => array(
'host' => '117.111.111.111', // 
'username' => 'root',
'password' => '',
'key' => '/Users/username/.ssh/id_rsa',
'keyphrase' => '',
'root' => '/var/webroot',
),
),
Copy after login

You can choose the username and password method for server authentication, or you can set the Key .

配置完成后调用:

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

就可以实时查看 Log 输出了:

How to view logs in laravel terminal

查看支持的参数

php artisan help tail
Copy after login

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

Laravel5 快速认证逻辑流程的分析

The above is the detailed content of How to view logs in laravel terminal. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template