VOOZH about

URL: https://deepwiki.com/hypervel/testbench/6.5-logging-queue-and-exception-configuration

⇱ Logging, Queue, and Exception Configuration | hypervel/testbench | DeepWiki


Loading...
Last indexed: 7 February 2026 (93289f)
Menu

Logging, Queue, and Exception Configuration

Purpose and Scope

This document covers three critical runtime configuration files in the workbench environment: logging, queue, and exception handling. These configurations control how the application logs messages, processes background jobs, and handles errors during test execution.

For general configuration concepts, see Configuration Management. For application-level configuration like environment and debug settings, see Application Configuration. For database configuration, see Database Configuration.

Configuration Files Overview

The testbench workbench provides three configuration files that manage runtime behavior:

Configuration FilePurposePrimary Components
workbench/config/logging.phpDefines logging channels and handlersMonolog channels, handlers, processors
workbench/config/queue.phpConfigures queue connections and failure handlingQueue drivers, batching, failed job storage
workbench/config/exceptions.phpRegisters exception handlersHTTP exception handler bindings

These configurations integrate with Hyperf's and Hypervel's service providers to establish runtime services during test execution.

Configuration Integration Flow


Sources: workbench/config/logging.php1-27 workbench/config/queue.php1-21 workbench/config/exceptions.php1-11

Logging Configuration

The workbench/config/logging.php file configures Monolog-based logging channels for the application. This configuration determines where and how log messages are written during test execution.

Logging Structure


Sources: workbench/config/logging.php10-26

Configuration Keys

KeyValueDescription
default'stderr'Default logging channel name
channels.null.driver'monolog'Uses Monolog driver for null channel
channels.null.handlerNullHandler::classDiscards all log messages (useful for silencing logs in tests)
channels.stderr.driver'monolog'Uses Monolog driver for stderr channel
channels.stderr.levelenv('LOG_LEVEL', 'debug')Minimum log level (debug, info, notice, warning, error, critical, alert, emergency)
channels.stderr.handlerStreamHandler::classWrites logs to a stream
channels.stderr.formatterenv('LOG_STDERR_FORMATTER')Optional custom formatter class
channels.stderr.with.stream'php://stderr'Write logs to standard error output
channels.stderr.processors[PsrLogMessageProcessor::class]Process PSR-3 message placeholders

Default Channel: stderr

The default stderr channel workbench/config/logging.php10 is configured for test execution visibility. All log messages are written to php://stderr workbench/config/logging.php22 using Monolog\Handler\StreamHandler workbench/config/logging.php19

The log level is controlled by the LOG_LEVEL environment variable, defaulting to debug workbench/config/logging.php18 This ensures maximum verbosity during test execution, making it easier to diagnose test failures.

The Monolog\Processor\PsrLogMessageProcessor workbench/config/logging.php24 processes PSR-3 message placeholders like {variable} in log messages, replacing them with actual values from the context array.

Null Channel

The null channel workbench/config/logging.php12-14 uses Monolog\Handler\NullHandler to discard all log messages. This is useful in tests where you want to suppress log output without affecting the test logic.

Sources: workbench/config/logging.php1-27

Queue Configuration

The workbench/config/queue.php file configures queue connections, job batching, and failed job handling. In the testbench environment, the default queue connection is sync, which executes jobs synchronously, making tests predictable and easier to debug.

Queue Structure


Sources: workbench/config/queue.php6-20

Configuration Keys

KeyValueDescription
defaultenv('QUEUE_CONNECTION', 'sync')Default queue connection name
connections.sync.driver'sync'Synchronous queue driver (executes jobs immediately)
batching.databaseenv('DB_CONNECTION', 'sqlite')Database connection for job batching
batching.table'job_batches'Table name for batch metadata
failed.driverenv('QUEUE_FAILED_DRIVER', 'database-uuids')Failed job storage driver
failed.databaseenv('DB_CONNECTION', 'sqlite')Database connection for failed jobs
failed.table'failed_jobs'Table name for failed job records

Sync Queue Connection

The sync connection workbench/config/queue.php8-10 uses a synchronous driver that executes queued jobs immediately in the same process. This behavior is ideal for testing because:

  1. Predictability: Jobs execute immediately, making test assertions straightforward
  2. No Background Workers: Tests don't require running separate queue workers
  3. Simplified Debugging: Stack traces include the entire call chain from dispatch to execution

Job Batching

Job batching configuration workbench/config/queue.php12-15 specifies where batch metadata is stored. Batches allow you to dispatch multiple jobs as a group and track their collective progress.

The job_batches table stores information about:

  • Batch ID and name
  • Total jobs in the batch
  • Pending, processed, and failed job counts
  • Batch completion status

Failed Jobs

Failed job configuration workbench/config/queue.php16-20 determines how jobs that throw exceptions are recorded. The database-uuids driver stores failed jobs in the failed_jobs table with UUID identifiers.

Each failed job record includes:

  • UUID identifier
  • Queue connection name
  • Queue name
  • Job payload
  • Exception details
  • Failed timestamp

Sources: workbench/config/queue.php1-21

Exception Configuration

The workbench/config/exceptions.php file registers exception handlers that process uncaught exceptions during application execution. The testbench uses a custom ExceptionHandler class that can be extended for package-specific error handling logic.

Exception Handler Structure


Sources: workbench/config/exceptions.php6-10

Configuration Keys

KeyValueDescription
handler.http[Workbench\App\Exceptions\ExceptionHandler::class]Array of HTTP exception handlers

HTTP Exception Handler

The handler.http configuration workbench/config/exceptions.php7-9 registers the Workbench\App\Exceptions\ExceptionHandler class as the primary HTTP exception handler. This class is responsible for:

  1. Catching Exceptions: Intercepting uncaught exceptions during HTTP request processing
  2. Formatting Responses: Converting exceptions to appropriate HTTP responses
  3. Logging Errors: Recording exception details for debugging
  4. Custom Handling: Implementing package-specific exception logic

The handler array syntax allows multiple exception handlers to be registered. Hyperf's exception dispatcher will call each handler in order until one returns a response.

Sources: workbench/config/exceptions.php1-11

Configuration Integration in TestCase

The three configuration files integrate seamlessly with the TestCase lifecycle. When TestCase::setUp() creates the application instance, these configurations are loaded and used to initialize runtime services.

Configuration Loading Sequence


Sources: workbench/config/logging.php1-27 workbench/config/queue.php1-21 workbench/config/exceptions.php1-11

Environment Variable Usage

All three configuration files support environment variables for runtime customization:

ConfigurationEnvironment VariableDefaultPurpose
LoggingLOG_LEVEL'debug'Minimum log level for stderr channel
LoggingLOG_STDERR_FORMATTERnullCustom log formatter class
QueueQUEUE_CONNECTION'sync'Default queue connection
QueueQUEUE_FAILED_DRIVER'database-uuids'Failed job storage driver
QueueDB_CONNECTION'sqlite'Database for batching and failed jobs

These environment variables can be set in testbench.yaml or via the defineEnvironment() method in tests.

Testing Configuration Customization

Tests can customize these configurations using the defineEnvironment() method provided by the TestCase base class. For details on the defineEnvironment() hook, see Reloading and Environment Management.

Sources: workbench/config/logging.php18-20 workbench/config/queue.php6-18

Configuration File Relationships

The three configuration files work together to establish a complete runtime environment:


Cross-Configuration Dependencies

  1. Queue → Database: Queue batching and failed jobs both use the database connection specified in queue.php workbench/config/queue.php13-18

  2. Exception → Logging: Exception handlers typically log error details using the logging configuration

  3. Queue → Logging: Failed queue jobs are logged before being stored in the database

  4. All → Environment: All three configurations support environment variable customization for test flexibility

Sources: workbench/config/logging.php1-27 workbench/config/queue.php1-21 workbench/config/exceptions.php1-11

Summary

The three configuration files provide essential runtime services for the testbench environment:

  • logging.php: Configures Monolog channels with a default stderr channel for test visibility and a null channel for silencing logs
  • queue.php: Configures synchronous queue execution, job batching, and failed job storage using SQLite
  • exceptions.php: Registers the HTTP exception handler for processing uncaught errors

These configurations integrate with Hypervel's service providers during application bootstrapping, making logging, queuing, and exception handling services available throughout test execution. Tests can customize these configurations using the defineEnvironment() method for scenario-specific behavior.

Sources: workbench/config/logging.php1-27 workbench/config/queue.php1-21 workbench/config/exceptions.php1-11