Skip to content

Enable log debug record flushing after action level is hit #516

Closed
@wimulkeman

Description

@wimulkeman

Feature

In Monolog it is possible to use the FingersCrossedHandler. When this handler is used a user can set the option action_level in their config.

When the FingersCrossedHandler is used the following feature becomes available: Monolog will buffer all logrecords which match the defined level, but not write them to the log file. When a log record is given which is at or above the action_level the buffered records will be flushed to the log.

This feature enables the user to gather debug information in their codebase and only flush it to the logs when the actual error occurs.

Current support

Sentry already supports this up to a certain point because the handleBatch method is implemented in the SentryHandler class. When you custom wrap the SentryHandler in the FingersCrossedHandler the functionality becomes available. At the moment this requires an extension of Sentry\Laravel\LogChannel like the following for example.

<?php

namespace App\Log;

use Monolog\Handler\FingersCrossedHandler;
use Monolog\Handler\HandlerInterface;
use Sentry\Laravel\LogChannel as SentryLogChannel;

class SentryActionLevelLogChannel extends SentryLogChannel
{
    protected function prepareHandler(HandlerInterface $handler, array $config = [])
    {
        $handler = parent::prepareHandler($handler, $config);

        if (!empty($config['action_level'])) {
            $handler = new FingersCrossedHandler($handler, $config['action_level']);
        }

        return $handler;
    }
}

Suggested support

It would be a nice improvement if a user can provide the action_level configuration and sentry-laravel will act upon it by wrapping the SentryHandler in a FingersCrossedHandler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions