[GH-ISSUE #1455] Is it possible to set maxium logging level? #614

Closed
opened 2026-03-04 02:16:25 +03:00 by kerem · 3 comments
Owner

Originally created by @imaegoo on GitHub (Apr 17, 2020).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1455

Monolog version 1.25.3


Hi,

I am using monolog in Drupal. I am finding a way to print info & warn log to stdout, and print error log to stderr, if I configure 2 handlers, error log will appear in both stdout and stderr, that's not what I expected, error log should not print to stdout.

Here is what I configured.

services:
  # Monolog handlers.
  # https://github.com/Seldaek/monolog/blob/1.25.3/README.md
  monolog.handler.std_info:
    class: Monolog\Handler\StreamHandler
    arguments: ['php://stdout', '%monolog.level.info%']
  monolog.handler.std_error:
    class: Monolog\Handler\StreamHandler
    arguments: ['php://stderr', '%monolog.level.error%']

The StreamHandler only accept minimum logging level.

/**
 * @param string|int $level The minimum logging level at which this handler will be triggered
 */

Is it possible to set maxium logging level?

Thanks.

Originally created by @imaegoo on GitHub (Apr 17, 2020). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1455 Monolog version 1.25.3 ---- Hi, I am using monolog in **Drupal**. I am finding a way to print `info` & `warn` log to `stdout`, and print `error` log to `stderr`, if I configure 2 handlers, `error` log will appear in both `stdout` and `stderr`, that's not what I expected, `error` log should not print to `stdout`. Here is what I configured. ``` services: # Monolog handlers. # https://github.com/Seldaek/monolog/blob/1.25.3/README.md monolog.handler.std_info: class: Monolog\Handler\StreamHandler arguments: ['php://stdout', '%monolog.level.info%'] monolog.handler.std_error: class: Monolog\Handler\StreamHandler arguments: ['php://stderr', '%monolog.level.error%'] ``` The [StreamHandler](https://github.com/Seldaek/monolog/blob/1.25.3/src/Monolog/Handler/StreamHandler.php) only accept minimum logging level. ``` /** * @param string|int $level The minimum logging level at which this handler will be triggered */ ``` **Is it possible to set maxium logging level?** Thanks.
kerem 2026-03-04 02:16:25 +03:00
  • closed this issue
  • added the
    Support
    label
Author
Owner

@imaegoo commented on GitHub (Apr 20, 2020):

Finally I find a way.

  1. Configure info handler behind error handler.
  2. Set error handler $bubble as FALSE.
<!-- gh-comment-id:616257263 --> @imaegoo commented on GitHub (Apr 20, 2020): Finally I find a way. 1. Configure info handler behind error handler. 2. Set error handler `$bubble` as FALSE.
Author
Owner

@Seldaek commented on GitHub (May 11, 2020):

You can also use FilterHandler to only pass some exact levels into a given handler.

<!-- gh-comment-id:626726675 --> @Seldaek commented on GitHub (May 11, 2020): You can also use FilterHandler to only pass some exact levels into a given handler.
Author
Owner

@imaegoo commented on GitHub (May 11, 2020):

You can also use FilterHandler to only pass some exact levels into a given handler.

@Seldaek Thank you for the answer. I haven't noticed FilterHandler, it would help.

<!-- gh-comment-id:626734234 --> @imaegoo commented on GitHub (May 11, 2020): > You can also use FilterHandler to only pass some exact levels into a given handler. @Seldaek Thank you for the answer. I haven't noticed `FilterHandler`, it would help.
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#614
No description provided.