VOOZH about

URL: https://deepwiki.com/hypervel/sentry/4.1-log-feature-and-channels

⇱ Log Feature and Channels | hypervel/sentry | DeepWiki


Loading...
Menu

Log Feature and Channels

This document explains how the LogFeature class extends Hypervel's logging facade with custom Sentry channels and how the LogChannel class creates Monolog loggers configured for Sentry. It covers the registration process, channel factory implementations, and integration with Hypervel's logging system. For details about the Monolog handler implementation that processes log records, see page 4.2. For broader configuration options, see page 1.2.

Overview

The LogFeature class extends Hypervel's Log facade to add two custom logging drivers that route log records to Sentry:

Driver NameFactory ClassPurpose
sentryHypervel\Sentry\LogChannelBasic Sentry logging using standard Sentry\Monolog\Handler
sentry_logsHypervel\Sentry\Logs\LogChannelEnhanced logging with custom LogsHandler for batching and aggregation

Both drivers are always registered when the package is loaded, regardless of feature switcher settings. The LogFeature is unconditionally applicable via its isApplicable() method returning true.

Sources: src/Features/LogFeature.php11-28

LogFeature Architecture

LogFeature Registration and Channel Creation Flow


Sources: src/Features/LogFeature.php11-28

Feature Applicability

The LogFeature::isApplicable() method always returns true, meaning the Sentry log channels are unconditionally registered when the package is loaded. This differs from other features like CacheFeature or QueueFeature that check the Switcher configuration before registering.

Sources: src/Features/LogFeature.php13-16

Channel Registration Process

The LogFeature::register() method extends Hypervel's Log facade with two custom driver factories using the Log::extend() method. This registration happens during the service provider's registration phase.

Log Facade Extension Sequence


Sources: src/Features/LogFeature.php18-27

Driver Factory Callbacks

Each Log::extend() call registers a callback that instantiates and invokes the corresponding channel class:

Extension CallFactory CallbackChannel Class
Log::extend('sentry', ...)function ($app, array $config) { return (new LogChannel($app))($config); }Hypervel\Sentry\LogChannel
Log::extend('sentry_logs', ...)function ($app, array $config) { return (new LogsLogChannel($app))($config); }Hypervel\Sentry\Logs\LogChannel

The callbacks receive the application container and channel configuration, then instantiate the channel class and immediately invoke it with the configuration array.

Sources: src/Features/LogFeature.php20-26

LogChannel Implementation

The Hypervel\Sentry\LogChannel class extends Hypervel\Log\LogManager and provides a factory for creating Monolog\Logger instances configured with the Sentry Monolog handler.

Channel Factory Pattern

LogChannel Logger Creation Process


Sources: src/LogChannel.php12-28

Handler Configuration Details

The LogChannel::__invoke() method creates and configures a Sentry\Monolog\Handler with the following parameters:

ParameterValueLine ReferenceDescription
HubSentrySdk::getCurrentHub()src/LogChannel.php17The current Sentry hub instance for event capture
Level$config['level'] ?? Logger::DEBUGsrc/LogChannel.php18Minimum log level to send to Sentry (defaults to DEBUG)

The handler is then processed by the inherited prepareHandler() method from LogManager, which applies any configured formatters and processors before being passed to the Monolog\Logger constructor.

Sources: src/LogChannel.php16-19 src/LogChannel.php24

LogChannel Method Flow

The __invoke() method executes these steps:

  1. Handler Creation (lines 16-19): Instantiates Sentry\Monolog\Handler with the current hub and log level
  2. Channel Name Parsing (line 22): Calls inherited parseChannel() to extract the channel name from configuration
  3. Handler Preparation (line 24): Calls inherited prepareHandler() to apply formatters and processors
  4. Logger Construction (lines 21-26): Creates and returns a Monolog\Logger instance with the parsed channel name and prepared handler

Sources: src/LogChannel.php14-27

Channel Usage in Configuration

Logging Configuration Example

Once registered, the channels can be used in Hypervel's logging configuration:


Integration Points

The log channels integrate with multiple system components:

  • Feature Switcher: Controls activation via tracing and breadcrumb settings
  • Application Container: Provides dependency injection context
  • Sentry Hub: Receives log events for processing and transmission
  • Monolog: Provides the underlying logging infrastructure

Sources: src/Features/LogFeature.php21-27 src/LogChannel.php17-18