最近在开发一个处理用户提交数据的程序时,遇到了一个棘手的问题:用户输入的文本中包含各种非ASCII字符,例如中文、日文、特殊符号等等。这些字符导致程序在处理字符串时效率低下,甚至出现错误。为了解决这个问题,我尝试了多种方法,最终找到了voku/portable-ascii这个库。 Composer在线学习地址:学习地址
作为一名 laravel 开发者,你是否曾遇到以下场景:
tail -f storage/logs/laravel.log
grep
tail
artisan tail
这些问题不仅降低了我们的工作效率,也增加了排查问题的难度。我们渴望一种更优雅、更集成的方式来实时监控 Laravel 应用的日志。
幸运的是,知名的开源团队 Spatie 为我们带来了解决方案:
spatie/laravel-tail
artisan tail
spatie/laravel-tail
tail -f
使用 Composer 安装
spatie/laravel-tail
<pre class="brush:php;toolbar:false;">composer require spatie/laravel-tail
Composer 会自动下载并安装该包,并将其添加到你的
composer.json
如果你需要配置远程日志监控,或者想自定义一些默认行为,可以发布其配置文件:
<pre class="brush:php;toolbar:false;">php artisan vendor:publish --provider="Spatie\Tail\TailServiceProvider"
这会在
config
tail.php
现在,你就可以使用 <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false;">php artisan tail
1. 本地日志监控
最简单的用法是:
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false;">php artisan tail
这会实时显示你应用日志目录中最新修改的日志文件的内容,就像
tail -f
实用选项:
<pre class="brush:php;toolbar:false;">php artisan tail --lines=50
other-file.log
<pre class="brush:php;toolbar:false;">php artisan tail --file="other-file.log"
--clear
<pre class="brush:php;toolbar:false;">php artisan tail --clear
<pre class="brush:php;toolbar:false;">php artisan tail --grep="error"
这在查找特定错误或请求时非常有用。
2. 远程日志监控
这是
spatie/laravel-tail
config/tail.php
production
<pre class="brush:php;toolbar:false;">// config/tail.php
return [
'production' => [
'host' => env('TAIL_HOST_PRODUCTION', 'your_production_server_ip'),
'user' => env('TAIL_USER_PRODUCTION', 'ssh_username'),
'log_directory' => env('TAIL_LOG_DIRECTORY_PRODUCTION', '/var/www/your_app/storage/logs'),
'file' => env('TAIL_LOG_FILE_PRODUCTION', null), // null 会自动选择最新日志文件
],
// 你可以添加更多环境,例如 'staging', 'testing'
];建议将敏感信息(如主机、用户)放入
.env
<pre class="brush:php;toolbar:false;">php artisan tail production
你同样可以使用
--lines
--file
--clear
--grep
artisan
grep
--lines
--clear
artisan
config/tail.php
实际应用中,
spatie/laravel-tail
artisan tail
告别手动
tail -f
spatie/laravel-tail
spatie/laravel-tail
以上就是如何高效实时查看Laravel应用日志?Spatie/Laravel-Tail助你轻松搞定的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号