为什么 schedule:run 在 Laravel Vapor 上 运行 的日志没有保存在 Cloudwatch 中?

Why do logs that are run by schedule:run on Laravel Vapor not saving in Cloudwatch?

所以我的 Kernel.php $schedule->command('command:name')->hourly()->withoutOverlapping(); 中有这个,但它从不将日志存储在 Cloudwatch 中。但是,如果我 运行 使用 vapor command staging --command="php artisan command:name" 手动将其存储在 Cloudwatch 中。

我假设它与 Laravel Vapor 中基于 cron 的命令有关,将它们的输出存储到 /dev/null 但我可能是错的。我的目标是捕获这些日志,有帮助吗?进一步补充,我的命令基本上是从 API 中获取 50 条记录的数据。

这来自官方 Laravel Vapor 文档:

Log Messages

Due to Vapor limitations, log messages from scheduled tasks will not appear in AWS CloudWatch or Vapor UI. As a workaround, you should dispatch a queued job from your scheduled tasks and write log messages from your queued job.

当您执行 vapor command staging --command="php artisan command:name 时,您正在使用 CLI。此模式会生成日志,这就是您可以看到它们的原因。

通过在屏幕输出和日志文件之间做一个符号 link 解决了这个问题。感谢@koalaok. See his answere here

ln -sf /proc/1/fd/1 /var/log/laravel-scheduler.log

在我的 Kernel.php

$filePath = '/var/log/laravel-scheduler.log';;
$schedule->command('my sample command')->daily()->appendOutputTo($filePath);