在 CentOS 系统下,Laravel 的日志管理主要包括以下几个方面:
storage/logs
目录下。你可以使用以下命令查看日志文件:cd /path/to/your/laravel/project
ls -l storage/logs
.env
文件中设置日志级别:LOG_LEVEL=debug
或者在 config/logging.php
文件中修改默认的日志级别:
'default' => env('LOG_LEVEL', 'debug'),
config/logging.php
文件中配置日志轮转策略。例如,每天生成一个新的日志文件,并保留最近 14 天的日志:'channels' => [
// ...
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
],
],
Log
门面手动写入日志:\Log::info('这是一条 info 级别的日志');
\Log::error('这是一条 error 级别的日志');
rm -rf storage/logs/*.log
tail
命令实时查看日志文件的内容:tail -f storage/logs/laravel.log
或者使用第三方工具(如 logwatch
或 goaccess
)对日志进行分析和监控。
通过以上方法,你可以在 CentOS 系统下有效地管理 Laravel 的日志。