Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Nikola Posa:
Using Monolog with Zend Service Manager
Jun 16, 2017 @ 17:09:27

Nikola Posa has a new post to his site showing you how to can combine Monolog for logging with Zend Service Manager, a component from the Zend Framework, defining the logger as a service that can be easily used (and re-used) across an application.

Without any doubt, Monolog and Zend Service Manager are two libraries that are almost always found in the composer.json file require section of my projects. In case you didn't know, Monolog is a PSR-3 compliant logging library that allows you to save logs to various storage types and web services, while Zend Service Manager is a PSR-11 compliant dependency injection container and a service locator implementation that facilitates management of application dependencies.

In this post I'm gonna show you how the two can work together.

He starts with an example of configuring the ServiceManager instance with a factory dependency that manually creates the Monolog logger inline. While this works, it's not idea, mixing configuration and functionality. He shows how to refactor the same functionality into a factory class that performs the same function but isolates it from the configuration. He then takes this further and separates out the environment-specific configuration from the handling and, finally, shows the creation of a more general logging factory that allows the definition of different kinds of loggers based on the need.

tagged: monolog zendservicemanager component tutorial combine factory configuration

Link: http://blog.nikolaposa.in.rs/2017/06/12/using-monolog-with-zend-service-manager/


Trending Topics: