Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 4df2d3b

Browse files
authored
Queue logs (#11)
* fix changelog * use FQCN * use `make()` method * log sqs event * use context for job name * add changelog entry * use single log line
1 parent 08ab941 commit 4df2d3b

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Added maintenance mode support ([#7](https://github.com/cachewerk/bref-laravel-bridge/pull/7))
1010
- Support persistent PostgresSQL sessions with Octane ([#9](https://github.com/cachewerk/bref-laravel-bridge/pull/9))
11-
- Parse `Authorization: Basic` header into `PHP_AUTH_*` variables ([#9](https://github.com/cachewerk/bref-laravel-bridge/pull/10))
11+
- Parse `Authorization: Basic` header into `PHP_AUTH_*` variables ([#10](https://github.com/cachewerk/bref-laravel-bridge/pull/10))
12+
- Prepare Octane responses without `Content-Type` ([08ab941](08ab941ab734d636697847b036cd9ed5e31a30ad))
1213

1314
### Changed
1415
- Made `ServeStaticAssets` configurable ([19fb1ac](19fb1ac21fd7245a8bd529eb6325cea2308ffbf2))
1516
- Made shared `X-Request-ID` log context configurable ([bfbc249](bfbc2498d3b418f149aba3d3fe795073dfcb7b48))
17+
- Log SQS job events ([#11](https://github.com/cachewerk/bref-laravel-bridge/pull/11))
18+
- Collapse `Secrets` log message into single line ([#11](https://github.com/cachewerk/bref-laravel-bridge/pull/11))
1619

1720
## [v0.1.0] - 2022-05-18
1821
### Added

src/BrefServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Monolog\Formatter\JsonFormatter;
66

7+
use Illuminate\Log\LogManager;
78
use Illuminate\Contracts\Http\Kernel;
89
use Illuminate\Support\Facades\Config;
910
use Illuminate\Support\ServiceProvider;
@@ -85,7 +86,7 @@ protected function shareRequestContext()
8586

8687
$this->app->rebinding('request', function ($app, $request) {
8788
if ($request->hasHeader('X-Request-ID')) {
88-
$app->make('log')->shareContext([
89+
$app->make(LogManager::class)->shareContext([
8990
'requestId' => $request->header('X-Request-ID'),
9091
]);
9192
}

src/Queue/QueueHandler.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Illuminate\Contracts\Events\Dispatcher;
1414
use Illuminate\Contracts\Debug\ExceptionHandler;
1515

16+
use Illuminate\Log\LogManager;
17+
1618
use Illuminate\Queue\SqsQueue;
1719
use Illuminate\Queue\Jobs\SqsJob;
1820
use Illuminate\Queue\QueueManager;
@@ -39,7 +41,7 @@ public function __construct(
3941
protected string $connection,
4042
protected string $queue,
4143
) {
42-
$queue = $container->get(QueueManager::class)
44+
$queue = $container->make(QueueManager::class)
4345
->connection($connection);
4446

4547
if (! $queue instanceof SqsQueue) {
@@ -105,6 +107,9 @@ protected function process(string $connectionName, SqsJob $job): void
105107
*/
106108
protected function raiseBeforeJobEvent(string $connectionName, SqsJob $job): void
107109
{
110+
$this->container->make(LogManager::class)
111+
->info("Processing job {$job->getJobId()}", ['name' => $job->resolveName()]);
112+
108113
$this->events->dispatch(new JobProcessing($connectionName, $job));
109114
}
110115

@@ -113,6 +118,9 @@ protected function raiseBeforeJobEvent(string $connectionName, SqsJob $job): voi
113118
*/
114119
protected function raiseAfterJobEvent(string $connectionName, SqsJob $job): void
115120
{
121+
$this->container->make(LogManager::class)
122+
->info("Processed job {$job->getJobId()}", ['name' => $job->resolveName()]);
123+
116124
$this->events->dispatch(new JobProcessed($connectionName, $job));
117125
}
118126

@@ -121,6 +129,9 @@ protected function raiseAfterJobEvent(string $connectionName, SqsJob $job): void
121129
*/
122130
protected function raiseExceptionOccurredJobEvent(string $connectionName, SqsJob $job, Throwable $th): void
123131
{
132+
$this->container->make(LogManager::class)
133+
->error("Job failed {$job->getJobId()}", ['name' => $job->resolveName()]);
134+
124135
$this->events->dispatch(new JobExceptionOccurred($connectionName, $job, $th));
125136
}
126137
}

src/Secrets.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ public static function injectIntoEnvironment(string $path, array $parameters)
2525
'WithDecryption' => true,
2626
]);
2727

28+
$injected = [];
29+
2830
foreach ($response['Parameters'] ?? [] as $secret) {
2931
$key = trim(strrchr($secret['Name'], '/'), '/');
30-
31-
fwrite(STDERR, sprintf(
32-
'%s: %s' . PHP_EOL,
33-
isset($_ENV[$key]) ? 'Overwriting runtime secret' : 'Injecting runtime secret',
34-
$key
35-
));
36-
32+
$injected[] = isset($_ENV[$key]) ? "{$key} (overwritten)" : $key;
3733
$_ENV[$key] = $secret['Value'];
3834
}
35+
36+
if (! empty($injected)) {
37+
fwrite(STDERR, 'Injected runtime secrets: ' . implode(', ', $injected) . PHP_EOL);
38+
}
3939
}
4040
}

0 commit comments

Comments
 (0)