Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Log Test Laravel Package

fig/log-test

Testing utilities for PSR-3 (psr/log): includes LoggerInterfaceTest for verifying LoggerInterface compliance and TestLogger mock for unit tests. Intended for dev/test use, with versions aligned to psr/log 1.x–3.x compatibility.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing fig/log-test as a require-dev dependency. Use version ^1.1 for psr/log ≥2.0 (including 3.x), and ^1.0 for PHP 7.x compatibility with psr/log ^1.1.14. Once installed, the two primary utilities are:

  • Psr\Log\Test\TestLogger: A test-friendly logger implementation that records all log calls in memory.
  • Psr\Log\Test\LoggerInterfaceTest: An abstract test class you extend to validate your custom logger implementation against the PSR-3 spec.

First use case: Write a unit test for your own PSR-3 logger. Extend LoggerInterfaceTest, implement getLogger() to return your logger instance, and run the inherited tests to catch spec violations.

Implementation Patterns

  • Testing your logger implementation: Extend LoggerInterfaceTest and implement the abstract getLogger() method to return your logger. The test suite runs PSR-3 compliance checks—including message formatting, context handling, and level validation.
  • Mocking logs in feature/unit tests: Use TestLogger to capture log output in tests instead of relying on external handlers. Example:
    $logger = new TestLogger();
    $logger->warning('User login failed', ['user_id' => 123]);
    $this->assertTrue($logger->hasRecord('warning'));
    $this->assertEquals(123, $logger->getLastRecord()['context']['user_id']);
    
  • Interpolated message assertions (v1.2.0+): TestLogger supports optional PSR-3-style placeholder interpolation. Enable it via constructor flag (new TestLogger(interpolate: true)), then assert against the interpolated message key in records.
  • Strategic versioning: Lock fig/log-test to ^1.1 for PHP 8.0+ projects using psr/log ^2 or ^3. Use ^1.0 only if maintaining legacy PHP 7.4 support.

Gotchas and Tips

  • Context type widening: The context array accepts mixed[], and level is also mixed (not just string|int). This reflects real-world usage but requires type-aware assertions in tests.
  • hasRecord() quirks: This method only checks presence of any log record—no guarantees that level, message, or context keys exist in the record array. Avoid expecting fixed structure.
  • Version mismatch trap: psr/log 1.x already included these test utilities, but they were removed in 2.x+. fig/log-test re-introduces them for 2.x/3.x. Confusingly, Composer installs fig/log-test 1.0 for psr/log 1.x, but that version is effectively empty—it just re-exports classes already in psr/log.
  • Nullable/optional parameters: PHP 8.4+ strict typing may require explicit type declarations when overriding methods. The package adapts to union types (string|int|LogLevel::XX) but double-check method signatures in your tests.
  • Testing fallback: TestLogger is not a drop-in replacement for production logging—it bypasses handlers entirely. Use it only in tests to assert that and how logs were called, not how they were handled.
  • Upgrade path: When migrating from psr/log 1.x to 2.x/3.x, fig/log-test ensures continuity of your PSR-3 tests without rewrite. Just update require-dev and ensure psr/log version is compatible per the package’s version matrix.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport