Skip to content

Cast retention and batch size to int for Laravel 13 compatibility - #62

Open
b7s wants to merge 1 commit into
madebyoutside:masterfrom
b7s:fix/laravel-13-typed-parameters
Open

Cast retention and batch size to int for Laravel 13 compatibility#62
b7s wants to merge 1 commit into
madebyoutside:masterfrom
b7s:fix/laravel-13-typed-parameters

Conversation

@b7s

@b7s b7s commented Aug 13, 2026

Copy link
Copy Markdown

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 when CLOUDWATCH_LOG_RETENTION_DAYS / CLOUDWATCH_LOG_BATCH_SIZE are set (e.g. retention => '14'), the values are passed as strings to PhpNexus\Cwh\Handler\CloudWatch::__construct(), which strictly types them as int|null $retention and int $batchSize. This throws a TypeError.

On Laravel 12+, LogManager::get() wraps channel creation in a try/catch and 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.php
    • Cast retention to (int) (falls back to 14 when empty/unset)
    • Cast batch_size to (int) (falls back to 10000 when empty/unset)
    • Guard the credentials key lookup with ?? null so a missing credentials config no longer emits an undefined-array-key warning
  • tests/LoggerTest.php
    • Regression test covering string values sourced from env()

Testing

  • vendor/bin/phpunit6 tests, 15 assertions, OK (PHP 8.4.22, laravel/framework ^13.0)
  • Verified end-to-end in a real Laravel 13 app: Log::channel('cloudwatch') now resolves the PhpNexus\Cwh\Handler\CloudWatch handler 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.

…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.
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.

1 participant