Log Fake
Log Fake stats
- Downloads
- 2.1M
- Stars
- 381
- Open Issues
- 2
- Forks
- 30
A drop in fake logger for testing with the Laravel framework.
Summary of the Log Fake for Laravel Package
Log Fake is a Laravel package developed by Tim MacDonald that facilitates the faking of logging capabilities in Laravel applications, enhancing testing and debugging processes. This package is particularly useful for developers who utilize Laravel's logging services and need a straightforward way to assert and inspect logs during testing.
Key Features:
- Faking Loggers: Easily substitute the Laravel logger with a fake logger for testing purposes.
- Assertions: Extensive support for assertions such as
assertLogged,assertNotLogged,assertLoggedTimes, and more, allowing detailed testing of logging logic across different channels and stacks. - Support for Multiple Channels and Stacks: Tailor assertions for specific channels or stacks, ensuring logs are correctly routed and handled as expected in complex configurations.
- Inspection Tools: Functions like
dump(),dd(),logs(), andallLogs()offer insights into logged messages, aiding in debugging and verification of log contents. - PHP and Laravel Version Compatibility: Supports PHP versions 8.1 and 8.2, and Laravel versions 9.0 and 10.0.
Installation:
Install the package via Composer:
composer require timacdonald/log-fake --dev
Usage Example:
Here's a simple example demonstrating how to use Log Fake in a test:
public function testItLogsWhenAUserAuthenticates(){ LogFake::bind(); Log::info('User logged in.', ['user_id' => $user->id]); Log::assertLogged(fn (LogEntry $log) => $log->level === 'info' && $log->message === 'User logged in.' );}
Practical Use Cases:
- Testing: Verify that specific log entries are created under certain conditions without writing to actual log files.
- Debugging: Inspect and dump logs to understand application behavior without impacting performance or state.
Additional Notes:
The package encourages a concept of "Thanksware," urging users to thank other open-source maintainers, reflecting a community-driven approach to software development.
For more details and advanced usage, visit the official GitHub repository.
🐘 Core Team Member @laravel; 📦 Building packages for fun; 📣 Speaking, Blogging, Viming; ✌️ He/Him