Yii2: Proposal: Have you thought about using monolog as logger?

Created on 5 Mar 2017  路  19Comments  路  Source: yiisoft/yii2

Monolog used by many frameworks. Have you thought about using monolog instead own logger implementation?

P.S. I know about yii2-monolog extension. I mean core usage

enhancement

Most helpful comment

All 19 comments

I'm OK with replacing some implementations with better components. I haven't really compared Monolog to our implementation in detail. What are cons and pros?

Pros:

  • PSR3
  • [Many handlers] (https://github.com/Seldaek/monolog/tree/master/src/Monolog/Handler)
  • large community (49M installs)

Cons:

  • PSR3 (differ interface). I think it's resolvable using Yii::info() shortcuts
  • no alter to categories mechanics
  • no exclude

Changing interface is possible in 2.1 so PSR-3 could be excluded from the list of cons, I think.

How about performance? Logging is very central application thing so if Monolog is significantly slower, it would be seen immediately.

Well, monolog logger is just an observer that throws messages to handlers. So it is closer to yii target then yii logger. I think it is suitable to use same dispatcher with some additions doing this we can achieve same performance and increase count of handlers.
Smth like:

  • user call Dispatcher->log()
  • Dispatcher collects messages
  • application call flush
  • Dispatcher send messages to logger

Sounds interesting to try to me. @yiisoft/core-developers thoughts?

Support of Monolog is a matter of PSR-3 support. There was an issue about this already - #1676.

Also there is related issue #7555.
It actually may happen some extension for Monolog support already exists.

As i said earlier, there is extension yii2-monolog. We are talking about core usage and profit of many handlers already implemented

We are talking about core usage and profit of many handlers already implemented

Following this path, inside the core there should be support for PSR-3 compatible logger. Then monolog can be used as a particular one.
Including monolog as a a default log processor will create an external dependency, which contradicts #8452.

I think that would do. Overall Yii logging is implemented well so there's no intent dropping it in favor of anything to save maintenance cost.

I'll leave it open since I want to try creating PSR-3 target for our logger.

For 2.1 we may consider either making out logger PSR-3 compatible or replacing it with Monolog.

It is available to make Logger psr-compatible without breaking BC if Yii uses only shortcuts. What you think about it? I can prepare PR

@antonmarin I don't think you can make Yii logger PSR-compatible in 2.0.x because PSR-3 requires absence of non-standard log levels.

Users SHOULD NOT use a custom level without knowing for sure the current implementation supports it.

Sounds like recommendation and we can split logger to Logger and Profiler. @samdark what is your opinion about this way?

Right. It's a recommendation. Worth trying then...

PR opened: #14611

Resolved via #14611

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Locustv2 picture Locustv2  路  3Comments

kminooie picture kminooie  路  3Comments

AstRonin picture AstRonin  路  3Comments

indicalabs picture indicalabs  路  3Comments

sobit picture sobit  路  3Comments