Cast retention and batch size to int for Laravel 13 compatibility - #62
Open
b7s wants to merge 1 commit into
Open
Cast retention and batch size to int for Laravel 13 compatibility#62b7s wants to merge 1 commit into
b7s wants to merge 1 commit into
Conversation
…handler Values sourced from environment variables via env() are strings, but the PhpNexus\Cwh\Handler\CloudWatch constructor requires an int for retention and batch size. On Laravel 13 this throws a TypeError, which is silently swallowed by the LogManager and replaced with the emergency logger, so logs silently stop reaching CloudWatch. Also guard the credentials lookup so a missing credentials key does not emit an undefined array key warning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the CloudWatch channel failing silently on Laravel 13 (and 11/12) when the channel is configured with environment variables, as documented in the readme.
Problem
env()always returns strings, so whenCLOUDWATCH_LOG_RETENTION_DAYS/CLOUDWATCH_LOG_BATCH_SIZEare set (e.g.retention => '14'), the values are passed as strings toPhpNexus\Cwh\Handler\CloudWatch::__construct(), which strictly types them asint|null $retentionandint $batchSize. This throws aTypeError.On Laravel 12+,
LogManager::get()wraps channel creation in atry/catchand silently swaps in the emergency logger when a driver factory throws. The result: the channel resolves,Log::channel('cloudwatch')appears to work, but log records go to the default stream handler instead of CloudWatch — no exception is ever surfaced.Changes
src/Logger.phpretentionto(int)(falls back to14when empty/unset)batch_sizeto(int)(falls back to10000when empty/unset)credentialskey lookup with?? nullso a missingcredentialsconfig no longer emits an undefined-array-key warningtests/LoggerTest.phpenv()Testing
vendor/bin/phpunit— 6 tests, 15 assertions, OK (PHP 8.4.22,laravel/framework ^13.0)Log::channel('cloudwatch')now resolves thePhpNexus\Cwh\Handler\CloudWatchhandler with the configured formatter and logs without error.Ref: open issue #61 (Laravel 13 support is merged but unreleased); this makes the documented env-var configuration actually work on the supported framework versions.