Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Illuminate/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ public function listen(Closure $callback)
*/
protected function fireLogEvent($level, $message, array $context = [])
{
// Avoid dispatching the event multiple times if our logger instance is the
// LogManager. The child LogManager will handle dispatching the event.
if ($this->logger instanceof LogManager && $this->logger->getEventDispatcher() !== null) {
return;
}

// If the event dispatcher is set, we will pass along the parameters to the
// log listeners. These are useful for building profilers or other tools
// that aggregate all of the log messages for a given "request" cycle.
Expand Down
12 changes: 12 additions & 0 deletions tests/Integration/Log/LoggingIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Illuminate\Tests\Integration\Log;

use Illuminate\Log\Events\MessageLogged;
use Illuminate\Log\Logger;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use Orchestra\Testbench\TestCase;

Expand All @@ -13,4 +16,13 @@ public function testLoggingCanBeRunWithoutEncounteringExceptions()

Log::info('Hello World');
}

public function testCallingLoggerDirectlyDispatchesOneEvent()
{
Event::fake([MessageLogged::class]);

$this->app->make(Logger::class)->debug('my debug message');

Event::assertDispatchedTimes(MessageLogged::class, 1);
}
}