Skip to content

feat!: log queue worker output through LoggerInterface instead of error_log() - #633

Merged
markshust merged 2 commits into
developfrom
feature/queue-worker-logger
Nov 1, 2026
Merged

markshust merged 2 commits into
developfrom
feature/queue-worker-logger

Conversation

@markshust

Copy link
Copy Markdown
Collaborator

Summary

Worker and FailedJobHandler now log through marko/log's LoggerInterface instead of calling error_log(). No error_log() calls are left in packages/queue/src.

Level Line
info [marko/queue] Worker stopping: ... (once per run, including the timeout path inside the alarm handler)
warning A job sets a timeout but ext-pcntl is not loaded
error Pop failure (worker keeps polling), job exceeded its timeout, timed-out job could not be released or failed, failed() hook threw

Tests pass a FakeLogger and assert on its entries, including the levels. The ini_set('error_log', ...) capture helpers in WorkerTest, WorkerLimitsTest, FailedJobHandlerTest and UniqueJobTest are gone, so the worker suite prints nothing extra.

Decisions

  • Hard-require marko/log, no queue-owned logging contract. marko/log is small (core, clock, config), owns LoggerInterface and binds it itself, and FakeLogger already exists for tests. A second queue-only logging contract would duplicate it.
  • Messages keep the [marko/queue] prefix. The log channel is app-wide (log.channel), so the prefix is what tells you which package a line came from. The message text is unchanged.
  • The logger is a required constructor argument on both classes. Worker takes it after $clock and before the defaulted $processControl. FailedJobHandler takes it last. A default would mean a silent fallback.
  • Integration fixtures (INTEGRATION_MODULES, QUEUE_SESSION_MODULES) now link log + log-file, and each fixture has a config/log.php that writes logs into its temporary project instead of the cwd.

Breaking changes

  • Apps using marko/queue need a marko/log handler package. Resolving Worker (and SyncQueue/DatabaseQueue, which use FailedJobHandler) resolves LoggerInterface. With marko/log installed but no handler, that throws NoDriverException, which names the packages to install. Upgrade: composer require marko/log-file, or marko/log-stream with LOG_HANDLERS=stream to keep worker lines on STDERR as before.
  • Code that builds these classes by hand: new Worker($queue, $failedJobHandler, $config, $jobRunner, $retryPolicy, $clock, $logger) and new FailedJobHandler($failedJobs, $envelope, $jobRunner, $eventDispatcher, $clock, $logger). Code that relies on the container needs no change.

Both are covered in a new "Upgrading: worker logs go through LoggerInterface" note on the queue docs page.

Docs

queue.md has a new Worker Logs section: where logs go (log.handlers: storage/logs with log-file, STDERR/STDOUT with log-stream), the level of each line, and how to test with FakeLogger. The install section, the pop-failure, pcntl-warning, stop-reason and failed() notes, the FailedJobHandler API reference and the testing example were updated to match. The testing example was also missing the $clock argument, which is now added.

Tests

  • composer ci passes locally (13680 passed, phpcs, php-cs-fixer, phpstan, docs:lint).
  • The integration-services group passes locally against Postgres and Redis for tests/Integration, queue-database and queue-redis, including queue:work in both fixture apps.

Fixes #608

🤖 Generated with Claude Code

https://claude.ai/code/session_017KaHtaJjfe2D38CdEdnmTb

@markshust markshust added breaking Introduces a breaking change enhancement New feature or request labels Nov 1, 2026
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Nov 1, 2026
markshust and others added 2 commits November 1, 2026 08:19
…or_log()

Worker and FailedJobHandler now take marko/log's LoggerInterface and log
stop lines (info), the missing-pcntl warning (warning), and pop failures,
timeouts and throwing failed() hooks (error) through it. Tests pass a
FakeLogger and assert on its entries, so the worker suite no longer prints
"Worker stopping" lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017KaHtaJjfe2D38CdEdnmTb
@markshust
markshust force-pushed the feature/queue-worker-logger branch from a82a054 to 0923bcd Compare November 1, 2026 13:22
@markshust
markshust merged commit eed4923 into develop Nov 1, 2026
5 checks passed
@markshust
markshust deleted the feature/queue-worker-logger branch November 1, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Introduces a breaking change enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Queue: inject a logger into Worker instead of calling error_log()

1 participant