Download the PHP package fluffy/monolog-cascade-namespaced without Composer
On this page you can find all versions of the php package fluffy/monolog-cascade-namespaced. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fluffy/monolog-cascade-namespaced
More information about fluffy/monolog-cascade-namespaced
Files in fluffy/monolog-cascade-namespaced
Package monolog-cascade-namespaced
Short Description Monolog cascade extension allows to configure loggers for a specific namespace/class (log4j style)
License MIT
Homepage https://github.com/PavelLoparev/monolog-cascade-namespaced
Informations about the package monolog-cascade-namespaced
Monolog Cascade Namespaced
What is Monolog Cascade Namespaced?
Monolog Cascade Namespaced is a Monolog Cascade extension that allows you to configure loggers for a specific namespace/class.
Installation
Add monolog-cascade-namespaced
as a requirement in your composer.json
file or run:
Note: Monolog Cascade requires PHP 5.3.9 or higher.
Usage
Load configuration (Monolog cascade supports the following config formats: yml
, json
and php
):
Then just use your logger:
Note: You must pass a full class name into CascadeNamespaced::getLogger()
method in order to have possibility to configure this logger in your configuration file in the future if you want it to have specific configuration. You can get a full class name with a help of get_called_class()
function.
Configuring
Root logger
Define root
logger in your cascade configuration. It will be returned by CascadeNamespaced::getLogger(get_called_class())
if there are no any specific loggers defined for your namespace/class. It's default logger for your application. If there is no root
logger defined then default monolog logger will be returned.
Namespace/Class specific loggers
Let's say you have next classes:
And you want to log messages from MyNamespace\SubNamespace
namespace classes into the stdout, but messages from MyNamespace\Class1
and MyNamespace\Class2
classes into two different files. It can be done with next configuration:
For other classes CascadeNamespaced
will return root
logger as a default logger for the application.
Tests
License
Monolog Cascade Namespaced is licensed under the MIT License - see the LICENSE
file for details.