Skip to content

Commit 16c9565

Browse files
committed
v2
1 parent 3a152e7 commit 16c9565

13 files changed

Lines changed: 742 additions & 216 deletions

.github/workflows/tests.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
include:
14+
- php: "8.2"
15+
testbench: "^10.13"
16+
suite: "laravel-12"
17+
- php: "8.3"
18+
testbench: "^10.13"
19+
suite: "laravel-12"
20+
- php: "8.3"
21+
testbench: "^11.1"
22+
suite: "laravel-13"
23+
- php: "8.4"
24+
testbench: "^11.1"
25+
suite: "laravel-13"
26+
- php: "8.5"
27+
testbench: "^11.1"
28+
suite: "laravel-13"
29+
30+
name: PHP ${{ matrix.php }} / ${{ matrix.suite }}
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- uses: shivammathur/setup-php@v2
36+
with:
37+
php-version: ${{ matrix.php }}
38+
coverage: none
39+
40+
- uses: ramsey/composer-install@v3
41+
with:
42+
dependency-versions: highest
43+
composer-options: --no-interaction --no-progress --prefer-dist
44+
45+
- name: Validate composer.json
46+
run: composer validate --strict
47+
48+
- name: Align Testbench version
49+
run: composer update orchestra/testbench --with="orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-progress --prefer-dist
50+
51+
- name: Run test suite
52+
run: composer test
53+
54+
analyse:
55+
runs-on: ubuntu-latest
56+
57+
steps:
58+
- uses: actions/checkout@v4
59+
60+
- uses: shivammathur/setup-php@v2
61+
with:
62+
php-version: "8.5"
63+
coverage: none
64+
65+
- uses: ramsey/composer-install@v3
66+
with:
67+
dependency-versions: highest
68+
composer-options: --no-interaction --no-progress --prefer-dist
69+
70+
- name: Validate composer.json
71+
run: composer validate --strict
72+
73+
- name: Run static analysis
74+
run: composer analyse

.gitignore

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
# OS
2-
.DS_Store
3-
Thumbs.db
4-
5-
# IDE and local environment
6-
/.vscode/
7-
/.vagrant/
8-
# JetBrains IDEs
9-
/.idea/
10-
111
# Packages
122
/composer.lock
133
/vendor/
144

155
# Tests
166
/build/
177
.php_cs.cache
18-
.phpunit.result.cache
8+
.phpstan.cache
9+
.phpunit.cache/

.travis.yml

Lines changed: 0 additions & 91 deletions
This file was deleted.

README.md

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,98 @@
11
# Laravel Queue Event Logger
22

3-
[![Build Status](https://travis-ci.com/larawelders/queue-event-logger.svg?branch=master)](https://travis-ci.com/github/larawelders/queue-event-logger)
3+
Log Laravel queue worker lifecycle events to a dedicated `queue` log channel.
44

5-
Log all details of queue events
5+
## Support Matrix
66

7-
### TODO
7+
| Package | PHP | Laravel |
8+
| ------- | --- | ------- |
9+
| `2.x` | `8.2+` | `12.x` / `13.x` |
810

9-
Write about self-contained jobs!
11+
Notes:
12+
13+
- Laravel 12 supports PHP `8.2` through `8.5`.
14+
- Laravel 13 requires PHP `8.3+`, so PHP `8.2` is only valid with Laravel 12.
15+
16+
## What It Logs
17+
18+
- `JobProcessing`
19+
- `JobProcessed`
20+
- `JobQueued`
21+
- `JobExceptionOccurred`
22+
- `JobReleasedAfterException`
23+
- `JobFailed`
24+
- `JobTimedOut`
25+
- `Looping`
26+
- `QueueBusy`
27+
- `QueueFailedOver`
28+
- `QueuePaused`
29+
- `QueueResumed`
30+
- `WorkerStarting`
31+
- `WorkerStopping`
32+
33+
## Installation
34+
35+
```bash
36+
composer require larawelders/queue-event-logger
37+
```
38+
39+
The package uses Laravel package discovery, so no manual provider registration is required.
40+
41+
The package registers a default `queue` log channel at runtime if your application does not already define one. By default, it uses a `single` channel that writes to `storage/logs/queue.log`.
42+
43+
If you want to customize the channel name or logger configuration, publish the package config:
44+
45+
```bash
46+
php artisan vendor:publish --tag=queue-event-logger-config
47+
```
48+
49+
The published config lets you change both the channel name and the underlying channel definition:
50+
51+
```php
52+
'channel' => 'queue',
53+
54+
'channel_config' => [
55+
'driver' => 'single',
56+
'path' => storage_path('logs/queue.log'),
57+
'level' => 'debug',
58+
],
59+
```
60+
61+
If your application already defines a channel with the configured name in `config/logging.php`, the application definition takes precedence:
62+
63+
```php
64+
'channels' => [
65+
'queue' => [
66+
'driver' => 'single',
67+
'path' => storage_path('logs/app-queue.log'),
68+
'level' => 'info',
69+
],
70+
],
71+
```
72+
73+
## Example Output
74+
75+
```text
76+
[8f4d4f2e] Processing job App\Jobs\ProcessWebhook
77+
[8f4d4f2e] Processed job App\Jobs\ProcessWebhook
78+
[8f4d4f2e] Queued job App\Jobs\ProcessWebhook on queue webhooks with delay 30
79+
[8f4d4f2e] Uncaught exception RuntimeException in job App\Jobs\ProcessWebhook: API timeout
80+
[8f4d4f2e] Released job after exception App\Jobs\ProcessWebhook with backoff 30
81+
[8f4d4f2e] Job failed RuntimeException in job App\Jobs\ProcessWebhook: API timeout
82+
[8f4d4f2e] Timed out job App\Jobs\ProcessWebhook
83+
[worker] Looping
84+
[worker] Queue webhooks on connection redis is busy with 250 pending jobs
85+
[worker] Queue failover from connection redis for job App\Jobs\ProcessWebhook after RuntimeException: Redis down
86+
[worker] Paused queue webhooks on connection redis for 60
87+
[worker] Resumed queue webhooks on connection redis
88+
[worker] Starting connection redis on queue webhooks
89+
[worker] Stopping with status 0
90+
```
91+
92+
## Development
93+
94+
```bash
95+
composer install
96+
composer run test
97+
composer run analyse
98+
```

composer.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
{
22
"name": "larawelders/queue-event-logger",
33
"type": "library",
4-
"description": "Log all details of queue events",
4+
"description": "Log Laravel queue worker lifecycle events",
55
"license": "MIT",
66
"require": {
7-
"php": "^7.2 || ^8.0",
8-
"laravel/framework": "^6.0 || ^7.0 || ^8.0"
7+
"php": "^8.2",
8+
"illuminate/contracts": "^12.0 || ^13.0",
9+
"illuminate/queue": "^12.0 || ^13.0",
10+
"illuminate/support": "^12.0 || ^13.0"
911
},
1012
"require-dev": {
11-
"nunomaduro/larastan": "^0.6.9",
12-
"mockery/mockery": "^1.3.1",
13-
"phpunit/phpunit": "^8.0 || ^9.0",
14-
"laravel/laravel": "^6.0 || ^7.0 || ^8.0"
13+
"larastan/larastan": "^3.9",
14+
"mockery/mockery": "^1.6",
15+
"orchestra/testbench": "^10.13 || ^11.1",
16+
"phpunit/phpunit": "^11.5 || ^12.0"
1517
},
1618
"autoload": {
1719
"psr-4": {
@@ -30,11 +32,12 @@
3032
]
3133
},
3234
"branch-alias": {
33-
"dev-master": "1.0-dev"
35+
"dev-master": "2.0-dev"
3436
}
3537
},
3638
"prefer-stable": true,
3739
"scripts": {
38-
"test": "phpunit --verbose"
40+
"analyse": "vendor/bin/phpstan analyse",
41+
"test": "vendor/bin/phpunit"
3942
}
4043
}

config/queue-event-logger.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
return [
6+
'channel' => 'queue',
7+
8+
'channel_config' => [
9+
'driver' => 'single',
10+
'path' => storage_path('logs/queue.log'),
11+
'level' => 'debug',
12+
],
13+
];

phpstan.neon.dist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
includes:
2+
- vendor/larastan/larastan/extension.neon
3+
4+
parameters:
5+
level: 7
6+
paths:
7+
- src/
8+
- tests/

0 commit comments

Comments
 (0)