[GH-ISSUE #1378] Level is not being read from config for custom handler #576

Closed
opened 2026-03-04 02:16:06 +03:00 by kerem · 1 comment
Owner

Originally created by @mattdillon100 on GitHub (Sep 13, 2019).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1378

I am using Monolog version 1 with Symfony.

I'm not sure that this should be asked here or in the Symfony repo but will ask here first.

I have created a custom handler to push logs to AWS Firehose. Here is the constructor:

class FirehoseLogHandler extends AbstractProcessingHandler {

public function __construct(
        FirehoseClient $firehoseClient,
        FormatterInterface $formatter,
        $streamName,
        $level = Logger::INFO,
        $bubble = true
    ) {

        $this->firehoseClient = $firehoseClient;
        $this->streamName = $streamName;
        $this->formatter = $formatter;

        parent::__construct($level, $bubble);
    }

And here is my monolog.yaml config:

monolog:
  handlers:
    firehose_handler:
      type: service
      id: kinesis_stream_handler

    main:
      type: stream
      handler: firehose_handler
      level: error
      channels: ["!event"]

services:
  kinesis_stream_handler:
    class: App\Logger\Handler\FirehoseLogHandler
    arguments:
      $firehoseClient: '@aws.firehose'
      $formatter: '@App\Logger\Formatter\FirehoseLogFormatter'
      $streamName: 'firehose-stream-test'

The problem that I am having is that the $level is always set to Logger::INFO (200), or whatever is set in the constructor. It seems to be ignoring what is set in the yaml config

Originally created by @mattdillon100 on GitHub (Sep 13, 2019). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1378 I am using Monolog version 1 with Symfony. I'm not sure that this should be asked here or in the Symfony repo but will ask here first. I have created a custom handler to push logs to AWS Firehose. Here is the constructor: ``` class FirehoseLogHandler extends AbstractProcessingHandler { public function __construct( FirehoseClient $firehoseClient, FormatterInterface $formatter, $streamName, $level = Logger::INFO, $bubble = true ) { $this->firehoseClient = $firehoseClient; $this->streamName = $streamName; $this->formatter = $formatter; parent::__construct($level, $bubble); } ``` And here is my `monolog.yaml` config: ``` monolog: handlers: firehose_handler: type: service id: kinesis_stream_handler main: type: stream handler: firehose_handler level: error channels: ["!event"] services: kinesis_stream_handler: class: App\Logger\Handler\FirehoseLogHandler arguments: $firehoseClient: '@aws.firehose' $formatter: '@App\Logger\Formatter\FirehoseLogFormatter' $streamName: 'firehose-stream-test' ``` The problem that I am having is that the `$level` is always set to `Logger::INFO` (200), or whatever is set in the constructor. It seems to be ignoring what is set in the yaml config
kerem 2026-03-04 02:16:06 +03:00
  • closed this issue
  • added the
    Support
    label
Author
Owner

@alexandrmazur96 commented on GitHub (Sep 13, 2019):

Hi!

I think it happens because you do not pass the level parameter to firehose_handler.

As Symfony docs say:

This defines a stack of handlers and each handler is called in the order that it's defined.

But I can be wrong with this. Try to add level: error:

monolog:
  handlers:
    firehose_handler:
      type: service
      id: kinesis_stream_handler
      level: error

p.s. yes, this question should be to Symfony, not for Monolog. I guess.

<!-- gh-comment-id:531224055 --> @alexandrmazur96 commented on GitHub (Sep 13, 2019): Hi! I think it happens because you do not pass the `level` parameter to `firehose_handler`. As Symfony docs say: > This defines a stack of handlers and each handler is called in the order that it's defined. But I can be wrong with this. Try to add `level: error`: ``` monolog: handlers: firehose_handler: type: service id: kinesis_stream_handler level: error ``` p.s. yes, this question should be to Symfony, not for Monolog. I guess.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#576
No description provided.