简体   繁体   中英

Configure Monolog from Yaml file

We are use Monolog for logging in our project. Judging by documentation there is no way to configure Monolog from config file, no matter xml or yaml . But as far as know there is a way to do this in Symfony. Unfortunately it highly depends on other Symfony components which we cannot afford to import to out project.

So, the question is: is there any way to configure Monolog from yaml file without using Symfony components?

You might give Monolog Cascade a try.

From the Readme:

Monolog Cascade is a Monolog extension that allows you to set up and configure multiple loggers and handlers from a single config file.

Have you tried converting the XML to an array and using the loadFromExtension() as shown in this example: http://symfony.com/doc/current/cookbook/logging/monolog_email.html - see the php tab.

With Symfony, you might want to use Monolog-Bundle Detailed doc is here http://symfony.com/doc/current//logging.html

Monolog-Cascade and Monolog-Bundle do essentially the same thing, Cascade being more agnostic. Nothing prevents you from using Cascade if you want even with Symfony.

I would add that Monolog Bundle uses a static mapping between configuration keys and corresponding classes for Handlers, Formatters, Processors; whereas Cascade resolves all this dynamically and does not need to be modified to support new Handlers, Formatters, Processors, etc.

[Disclaimer]: I'm the author of Monolog-Cascade

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM