Skip to content

Commit 24029f7

Browse files
committed
rename to LogChannelBootstrapper, add to config
1 parent cef7f11 commit 24029f7

4 files changed

Lines changed: 27 additions & 26 deletions

File tree

assets/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
// Bootstrappers\RootUrlBootstrapper::class,
186186
// Bootstrappers\UrlGeneratorBootstrapper::class,
187187
// Bootstrappers\MailConfigBootstrapper::class,
188+
// Bootstrappers\LogChannelBootstrapper::class,
188189
// Bootstrappers\BroadcastingConfigBootstrapper::class,
189190
// Bootstrappers\BroadcastChannelPrefixBootstrapper::class,
190191

src/Bootstrappers/LogTenancyBootstrapper.php renamed to src/Bootstrappers/LogChannelBootstrapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Stancl\Tenancy\Contracts\Tenant;
1515

1616
/**
17-
* Enable tenant-specific logging.
17+
* Use tenant-specific logging channels.
1818
*
1919
* Channels included in the $storagePathChannels property will be configured
2020
* to write logs into the tenant's storage directory. The list includes
@@ -31,7 +31,7 @@
3131
*
3232
* @see Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper
3333
*/
34-
class LogTenancyBootstrapper implements TenancyBootstrapper
34+
class LogChannelBootstrapper implements TenancyBootstrapper
3535
{
3636
protected array $defaultConfig = [];
3737

tests/Bootstrappers/LogTenancyBootstrapperTest.php renamed to tests/Bootstrappers/LogChannelBootstrapperTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
use Stancl\Tenancy\Events\TenancyInitialized;
99
use Stancl\Tenancy\Listeners\BootstrapTenancy;
1010
use Stancl\Tenancy\Listeners\RevertToCentralContext;
11-
use Stancl\Tenancy\Bootstrappers\LogTenancyBootstrapper;
11+
use Stancl\Tenancy\Bootstrappers\LogChannelBootstrapper;
1212
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
1313
use Illuminate\Support\Facades\Log;
1414

1515
afterEach($cleanup = function () {
16-
LogTenancyBootstrapper::$channelOverrides = [];
17-
LogTenancyBootstrapper::$storagePathChannels = ['single', 'daily'];
16+
LogChannelBootstrapper::$channelOverrides = [];
17+
LogChannelBootstrapper::$storagePathChannels = ['single', 'daily'];
1818

1919
$logFiles = array_merge(
2020
glob(storage_path('logs/*.log')) ?: [],
@@ -31,7 +31,7 @@
3131
beforeEach(function () use ($cleanup) {
3232
config([
3333
'tenancy.bootstrappers' => [
34-
LogTenancyBootstrapper::class,
34+
LogChannelBootstrapper::class,
3535
],
3636
]);
3737

@@ -42,21 +42,21 @@
4242
});
4343

4444
test('storage path channels get tenant-specific paths by default', function () {
45-
// Note that for LogTenancyBootstrapper to change the paths correctly by default,
45+
// Note that for LogChannelBootstrapper to change the paths correctly by default,
4646
// the bootstrapper MUST run after FilesystemTenancyBootstrapper.
4747
config([
4848
'tenancy.bootstrappers' => [
4949
FilesystemTenancyBootstrapper::class,
50-
LogTenancyBootstrapper::class,
50+
LogChannelBootstrapper::class,
5151
],
5252
]);
5353

5454
$centralStoragePath = storage_path();
5555
$tenant = Tenant::create();
5656

5757
// Storage path channels are 'single' and 'daily' by default.
58-
// This can be customized via LogTenancyBootstrapper::$storagePathChannels.
59-
foreach (LogTenancyBootstrapper::$storagePathChannels as $channel) {
58+
// This can be customized via LogChannelBootstrapper::$storagePathChannels.
59+
foreach (LogChannelBootstrapper::$storagePathChannels as $channel) {
6060
$originalPath = config("logging.channels.{$channel}.path");
6161

6262
tenancy()->initialize($tenant);
@@ -78,7 +78,7 @@
7878
config([
7979
'tenancy.bootstrappers' => [
8080
FilesystemTenancyBootstrapper::class,
81-
LogTenancyBootstrapper::class,
81+
LogChannelBootstrapper::class,
8282
],
8383
'logging.channels.stack' => [
8484
'driver' => 'stack',
@@ -132,12 +132,12 @@
132132
$tenant = Tenant::create(['webhookUrl' => 'tenant-webhook']);
133133

134134
// Channel override closures must return an array, otherwise an exception is thrown
135-
LogTenancyBootstrapper::$channelOverrides['slack'] = fn (Tenant $tenant, array $channel) => 'invalid override';
135+
LogChannelBootstrapper::$channelOverrides['slack'] = fn (Tenant $tenant, array $channel) => 'invalid override';
136136

137137
expect(fn() => tenancy()->initialize($tenant))->toThrow(InvalidArgumentException::class);
138138

139139
// Test both array mapping and closure-based overrides
140-
LogTenancyBootstrapper::$channelOverrides = [
140+
LogChannelBootstrapper::$channelOverrides = [
141141
'slack' => ['url' => 'webhookUrl'], // slack.url will be mapped to $tenant->webhookUrl
142142
'single' => function (Tenant $tenant, array $channel) use ($centralStoragePath) {
143143
return array_merge($channel, ['path' => $centralStoragePath . "/logs/override-{$tenant->id}.log"]);
@@ -165,7 +165,7 @@
165165
test('channel config keys remain unchanged if the specified tenant override attribute is null', function() {
166166
config(['logging.channels.slack.username' => 'Default username']);
167167

168-
LogTenancyBootstrapper::$channelOverrides = [
168+
LogChannelBootstrapper::$channelOverrides = [
169169
'slack' => ['username' => 'nonExistentAttribute'], // $tenant->nonExistentAttribute
170170
];
171171

@@ -178,9 +178,9 @@
178178
test('channel overrides take precedence over the default storage path channel updating logic', function () {
179179
$tenant = Tenant::create(['id' => 'tenant1']);
180180

181-
LogTenancyBootstrapper::$storagePathChannels = ['single'];
181+
LogChannelBootstrapper::$storagePathChannels = ['single'];
182182

183-
LogTenancyBootstrapper::$channelOverrides = [
183+
LogChannelBootstrapper::$channelOverrides = [
184184
'single' => function (Tenant $tenant, array $channel) {
185185
return array_merge($channel, ['path' => storage_path("logs/override-{$tenant->id}.log")]);
186186
},
@@ -196,7 +196,7 @@
196196
config([
197197
'tenancy.bootstrappers' => [
198198
FilesystemTenancyBootstrapper::class,
199-
LogTenancyBootstrapper::class,
199+
LogChannelBootstrapper::class,
200200
],
201201
]);
202202

@@ -232,7 +232,7 @@
232232
config([
233233
'tenancy.bootstrappers' => [
234234
FilesystemTenancyBootstrapper::class,
235-
LogTenancyBootstrapper::class,
235+
LogChannelBootstrapper::class,
236236
],
237237
]);
238238

@@ -284,7 +284,7 @@
284284
// Channel overrides also override the default behavior for the storage path-based channels
285285
$tenant = Tenant::create(['id' => 'override-tenant']);
286286

287-
LogTenancyBootstrapper::$channelOverrides = [
287+
LogChannelBootstrapper::$channelOverrides = [
288288
'single' => function (Tenant $tenant, array $channel) {
289289
// The tenant log path will be set to storage/tenantoverride-tenant/logs/custom-override-tenant.log
290290
return array_merge($channel, ['path' => storage_path("logs/custom-{$tenant->id}.log")]);
@@ -303,7 +303,7 @@
303303
config([
304304
'tenancy.bootstrappers' => [
305305
FilesystemTenancyBootstrapper::class,
306-
LogTenancyBootstrapper::class,
306+
LogChannelBootstrapper::class,
307307
],
308308
'logging.channels.stack' => [
309309
'driver' => 'stack',
@@ -353,7 +353,7 @@
353353
config([
354354
'tenancy.bootstrappers' => [
355355
FilesystemTenancyBootstrapper::class,
356-
LogTenancyBootstrapper::class,
356+
LogChannelBootstrapper::class,
357357
],
358358
'logging.channels.custom_stack' => [
359359
'driver' => 'stack',
@@ -436,7 +436,7 @@
436436
$tenant2 = Tenant::create(['id' => 'tenant2', 'logging' => ['slackUrl' => 'tenant2-webhook']]);
437437

438438
// Attribute mapping using nested attributes (dot notation) works
439-
LogTenancyBootstrapper::$channelOverrides = [
439+
LogChannelBootstrapper::$channelOverrides = [
440440
'slack' => ['url' => 'logging.slackUrl'],
441441
];
442442

@@ -456,7 +456,7 @@
456456
config([
457457
'tenancy.bootstrappers' => [
458458
FilesystemTenancyBootstrapper::class,
459-
LogTenancyBootstrapper::class,
459+
LogChannelBootstrapper::class,
460460
],
461461
'logging.channels.stack' => [
462462
'driver' => 'stack',
@@ -502,7 +502,7 @@
502502

503503
// Valid override first, the config will be updated properly,
504504
// then an invalid override that will cause the configuration to fail and throw an exception.
505-
LogTenancyBootstrapper::$channelOverrides = [
505+
LogChannelBootstrapper::$channelOverrides = [
506506
'single' => ['path' => 'loggingPath'], // Valid override
507507
'slack' => fn () => 'invalid override',
508508
];

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Stancl\Tenancy\Bootstrappers\BroadcastingConfigBootstrapper;
2424
use Stancl\Tenancy\Bootstrappers\BroadcastChannelPrefixBootstrapper;
2525
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
26-
use Stancl\Tenancy\Bootstrappers\LogTenancyBootstrapper;
26+
use Stancl\Tenancy\Bootstrappers\LogChannelBootstrapper;
2727
use Stancl\Tenancy\Bootstrappers\DatabaseCacheBootstrapper;
2828
use Stancl\Tenancy\Bootstrappers\TenantConfigBootstrapper;
2929

@@ -193,7 +193,7 @@ protected function getEnvironmentSetUp($app)
193193
$app->singleton(RootUrlBootstrapper::class);
194194
$app->singleton(UrlGeneratorBootstrapper::class);
195195
$app->singleton(FilesystemTenancyBootstrapper::class);
196-
$app->singleton(LogTenancyBootstrapper::class);
196+
$app->singleton(LogChannelBootstrapper::class);
197197
$app->singleton(TenantConfigBootstrapper::class);
198198
}
199199

0 commit comments

Comments
 (0)