Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes logging of scheduled tasks #156

Merged
merged 1 commit into from
Jul 27, 2024
Merged

Conversation

aknosis
Copy link
Contributor

@aknosis aknosis commented Jul 27, 2024

Due to the way that Laravel executes scheduled tasks, coupled with bref sending everything to stderr (by default) logging inside of scheduled tasks end up in /dev/null.

In CloudWatch you will see commands run like so:


2024-07-26 18:44:10 Running ['artisan' example:command] ... 194ms DONE
--
⇂ '/opt/bin/php' 'artisan' example:command > '/dev/null' 2>&1

With this change you can now see logs:

2024-07-27 00:02:09 Running ['artisan' example:command] [2024-07-27 00:02:09] staging.DEBUG: first debug
--
[2024-07-27 00:02:09] staging.DEBUG: second debug
... 132ms DONE
⇂ '/opt/bin/php' 'artisan' example:command >> '/proc/1/fd/1' 2>&1

I didn't do any real in depth look into the availability of /proc/1/fd/1 but it would fail on my mac so I added the file_exists() check.

Can add tests if desired, hooking into this even seemed like the least intrusive way to accomplish this.

Copy link
Member

@mnapoli mnapoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reporting this, I'm surprised this is the first time we hear about it. But it seems that it also happens on Vapor: https://stackoverflow.com/questions/62485981/why-do-logs-that-are-run-by-schedulerun-on-laravel-vapor-not-saving-in-cloudwat

That would be great to solve this indeed 👍

src/BrefServiceProvider.php Show resolved Hide resolved
Copy link
Member

@mnapoli mnapoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I just caught up with the Slack thread, that answers my question :)

Thanks a lot for investigating and solving this!

@mnapoli mnapoli enabled auto-merge July 27, 2024 15:04
@mnapoli mnapoli disabled auto-merge July 27, 2024 15:17
@mnapoli mnapoli merged commit 75035b0 into brefphp:master Jul 27, 2024
12 checks passed
@aknosis aknosis deleted the fix-scheduler-logs branch July 27, 2024 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants