Log Fake for Laravel

Log Fake for Laravel

Log Fake is a drop-in fake logger for testing with the Laravel framework by Tim MacDonald (@timacdonald). The Log fake package gives you the ability to fake the logger in your application, including the ability to make assertions against channels and stacks introduced in Laravel 5.6.

Here’s a simple example of using the logger in a test:


use TiMacDonald\Log\LogFake;
use Illuminate\Support\Facades\Log;


Log::swap(new LogFake);

Log::info('Donuts have arrived');

Log::assertLogged('info', function ($message, $context) {
    return str_contains($message, 'Donuts');

As mentioned, this fake supports channels and stacks, so if you are logging to a specific channel in your app, you need to prefix your assertions with a given channel:


Log::channel('slack')->alert('It is 5pm, go home');

Log::channel('slack')->assertLogged('alert'); // passes

// without the channel prefix...

Log::assertLogged('alert');  // fails

Like channels, you will need to do the same thing for stacks:


Log::swap(new LogFake);

Log::stack(['bugsnag', 'sentry'])->critical('Perform evasive maneuvers');

Log::stack(['bugsnag', 'sentry'])->assertLogged('critical');  // passes

// without the stack prefix...

Log::assertLogged('critical'); // fails

The GitHub repo has a full list of available assertions and usage instructions, along with the source code.

Nice work Tim!

Filed in: News / logging


Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Full-Stack Laravel Developer
Revive Interior
Intermediate PHP Developer (Full Stack | CakePHP | Laravel | Vue | jQuery)
Senior PHP Developer (Full Stack | CakePHP | Laravel | Vue | jQuery)
Laravel Developer
Amsterdam (partially remote possible)
Let's Book
Web Developer (Laravel)
Tweed Heads, New South Wales, AUSTRALIA
Tursa Employment & Training
Laravel Experts needed-Remote position
Golden Sky ROI
Senior Backend Developer