Skip to content

Commit 5f36d4b

Browse files
authored
Merge pull request #510 from DirectoryTree/change-logging-channel
Add ability to set a logging channel
2 parents 0ed5d8d + ca70cab commit 5f36d4b

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

config/ldap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454

5555
'logging' => env('LDAP_LOGGING', true),
5656

57+
'logging_channel' => env('LOG_CHANNEL', 'stack'),
58+
5759
/*
5860
|--------------------------------------------------------------------------
5961
| LDAP Cache

src/LdapServiceProvider.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,16 @@ protected function registerLogging()
8282
return;
8383
}
8484

85-
if (! is_null($logger = Log::getFacadeRoot())) {
86-
Container::getInstance()->setLogger($logger);
85+
/** @var \Illuminate\Log\LogManager|null $logger */
86+
if (is_null($logger = Log::getFacadeRoot())) {
87+
return;
8788
}
89+
90+
Container::getInstance()->setLogger(
91+
($channel = Config::get('ldap.logging_channel'))
92+
? $logger->channel($channel)
93+
: $logger
94+
);
8895
}
8996

9097
/**

tests/Unit/LdapServiceProviderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace LdapRecord\Laravel\Tests\Unit;
44

5-
use Illuminate\Log\LogManager;
65
use LdapRecord\Connection;
76
use LdapRecord\Container;
87
use LdapRecord\Laravel\LdapServiceProvider;
98
use LdapRecord\Laravel\Tests\TestCase;
109
use LdapRecord\Query\Cache;
10+
use Psr\Log\LoggerInterface;
1111

1212
class LdapServiceProviderTest extends TestCase
1313
{
@@ -64,7 +64,7 @@ public function test_config_is_publishable()
6464

6565
public function test_logger_is_set_on_container_when_enabled()
6666
{
67-
$this->assertInstanceOf(LogManager::class, Container::getInstance()->getLogger());
67+
$this->assertInstanceOf(LoggerInterface::class, Container::getInstance()->getLogger());
6868
}
6969

7070
public function test_cache_is_set_on_connection_when_enabled()
@@ -143,6 +143,7 @@ public function test_env_config_is_loaded_and_cacheable()
143143
],
144144
],
145145
'logging' => true,
146+
'logging_channel' => 'stack',
146147
'cache' => [
147148
'enabled' => true,
148149
'driver' => 'array',

0 commit comments

Comments
 (0)