Skip to content

Commit

Permalink
Merge pull request #510 from DirectoryTree/change-logging-channel
Browse files Browse the repository at this point in the history
Add ability to set a logging channel
  • Loading branch information
stevebauman authored Feb 9, 2023
2 parents 0ed5d8d + ca70cab commit 5f36d4b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config/ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@

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

'logging_channel' => env('LOG_CHANNEL', 'stack'),

/*
|--------------------------------------------------------------------------
| LDAP Cache
Expand Down
11 changes: 9 additions & 2 deletions src/LdapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,16 @@ protected function registerLogging()
return;
}

if (! is_null($logger = Log::getFacadeRoot())) {
Container::getInstance()->setLogger($logger);
/** @var \Illuminate\Log\LogManager|null $logger */
if (is_null($logger = Log::getFacadeRoot())) {
return;
}

Container::getInstance()->setLogger(
($channel = Config::get('ldap.logging_channel'))
? $logger->channel($channel)
: $logger
);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/LdapServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace LdapRecord\Laravel\Tests\Unit;

use Illuminate\Log\LogManager;
use LdapRecord\Connection;
use LdapRecord\Container;
use LdapRecord\Laravel\LdapServiceProvider;
use LdapRecord\Laravel\Tests\TestCase;
use LdapRecord\Query\Cache;
use Psr\Log\LoggerInterface;

class LdapServiceProviderTest extends TestCase
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public function test_config_is_publishable()

public function test_logger_is_set_on_container_when_enabled()
{
$this->assertInstanceOf(LogManager::class, Container::getInstance()->getLogger());
$this->assertInstanceOf(LoggerInterface::class, Container::getInstance()->getLogger());
}

public function test_cache_is_set_on_connection_when_enabled()
Expand Down Expand Up @@ -143,6 +143,7 @@ public function test_env_config_is_loaded_and_cacheable()
],
],
'logging' => true,
'logging_channel' => 'stack',
'cache' => [
'enabled' => true,
'driver' => 'array',
Expand Down

0 comments on commit 5f36d4b

Please sign in to comment.