Package

Timacdonald Log Fake

A drop in fake logger for testing with the Laravel framework.

Package

timacdonald/log-fake

View on GitHub →

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 Log Fake Related Articles

Log Fake for Laravel image

Log Fake for Laravel

Read article
Laravel Log Fake 2.0 image

Laravel Log Fake 2.0

Read article
PHP Callable Fake Library image

PHP Callable Fake Library

Read article
Laravel Log Files Support in PhpStorm image

Laravel Log Files Support in PhpStorm

Read article
Log User Activity in Your Laravel App with Activity Log v5  image

Log User Activity in Your Laravel App with Activity Log v5

Read article
Laravel Fake Assertions Now Accept Property Arrays image

Laravel Fake Assertions Now Accept Property Arrays

Read article

Let your users buy domains without leaving your app

If your Laravel app gives users a site, a storefront, or a workspace, they’ll eventually want their own domain. The name.com API lets them search, register, and connect one without leaving your product. It’s a clean REST API, so Laravel’s HTTP client is all you need.

Let your users buy domains without leaving your app

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

PhpStorm

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

PhpStorm

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum

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