PSR-3 compliant test logger based on psr/log v1's, but compatible with v2 and v3 too!

v1.3.0 2023-11-29 23:03 UTC

This package is auto-updated.

Last update: 2024-04-30 00:00:14 UTC


Latest Version Total Downloads Software License Build Status Coverage Status Quality Score Psalm Type Coverage Sponsor development of this project

PSR-3 compliant test logger based on psr/log v1's, but compatible with v2 and v3 too!

📦 Installation

This project requires PHP 8.0 or higher. To install it via Composer simply run:

$ composer require --dev colinodell/psr-testlogger


This package provides a PSR-3 compliant logger useful for testing. Simply log messages to it like usual, and use one of the many available methods to perform assertions on the logged messages.

hasRecords(string|int $level): bool

hasEmergencyRecords(): bool
hasAlertRecords(): bool
hasCriticalRecords(): bool
hasErrorRecords(): bool
hasWarningRecords(): bool
hasNoticeRecords(): bool
hasInfoRecords(): bool
hasDebugRecords(): bool

hasRecord(string|array $record, string|int $level): bool

hasEmergency(string|array $record): bool
hasAlert(string|array $record): bool
hasCritical(string|array $record): bool
hasError(string|array $record): bool
hasWarning(string|array $record): bool
hasNotice(string|array $record): bool
hasInfo(string|array $record): bool
hasDebug(string|array $record): bool

hasRecordThatContains(string $message, string|int|null $level = null): bool

hasEmergencyThatContains(string $message): bool
hasAlertThatContains(string $message): bool
hasCriticalThatContains(string $message): bool
hasErrorThatContains(string $message): bool
hasWarningThatContains(string $message): bool
hasNoticeThatContains(string $message): bool
hasInfoThatContains(string $message): bool
hasDebugThatContains(string $message): bool

hasRecordThatMatches(string $regex, string|int|null $level = null): bool

hasEmergencyThatMatches(string $regex): bool
hasAlertThatMatches(string $regex): bool
hasCriticalThatMatches(string $regex): bool
hasErrorThatMatches(string $regex): bool
hasWarningThatMatches(string $regex): bool
hasNoticeThatMatches(string $regex): bool
hasInfoThatMatches(string $regex): bool
hasDebugThatMatches(string $regex): bool

hasRecordThatPasses(callable $predicate, string|int|null $level = null): bool

hasEmergencyThatPasses(callable $predicate): bool
hasAlertThatPasses(callable $predicate): bool
hasCriticalThatPasses(callable $predicate): bool
hasErrorThatPasses(callable $predicate): bool
hasWarningThatPasses(callable $predicate): bool
hasNoticeThatPasses(callable $predicate): bool
hasInfoThatPasses(callable $predicate): bool
hasDebugThatPasses(callable $predicate): bool

In addition to the standard PSR-3 log levels, this test logger also supports custom string and int levels when using log(). Other types are not supported.

Release Cycle

This library is considered stable. No new development is currently planned unless needed to fix issues or maintain compatibility with the psr/log library.

Issues and PRs for bug fixes are welcome and will be merged/released on an as-needed basis.

Backward Compatibility

This library strictly follows SemVer using Symfony's BC Promise as a guide.

Reporting Security Issues

Please report security issues directly to the library author instead of using the issue tracker. Contact info can be found in composer.json.