Log Fake

timacdonald/log-fake image

Log Fake stats

Downloads
2.1M
Stars
381
Open Issues
2
Forks
30

View on GitHub →

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(), and allLogs() 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.

timacdonald photo

🐘 Core Team Member @laravel; 📦 Building packages for fun; 📣 Speaking, Blogging, Viming; ✌️ He/Him

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Timacdonald Log Fake Related Articles

Laravel Log Fake 2.0 image

Laravel Log Fake 2.0

Read article
Log Fake for Laravel image

Log Fake for Laravel

Read article
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Tighten logo

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten