Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

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
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360° Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge