slaxweb / logger
Logger component for SlaxWeb Framework
Installs: 1 209
Dependents: 8
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.0.0
- monolog/monolog: ~1.22.0
Suggests
- pimple/pimple: Make use of available providers for Pimple version 3.0.x
- slaxweb/config: If you want to use the Factory or the Service Provider, Config component is required.
This package is not auto-updated.
Last update: 2024-11-23 17:34:59 UTC
README
The SlaxWeb\Logger component is only a simple wrapper around the Seldaek/monolog library to provide an easier integration into the SlaxWeb\Framework. It provides only a Service Provider for the Pimple Dependency Injection Container, and a Factory for instantiation of the logger library. The Logger component also depends on the Config component of the SlaxWeb\Framework.
Installation
Easiest method of installation is through composer, to install just edit your composer.json file to contain:
{ "require": { "slaxweb/logger": "~0.2" } }
Usage
To instantiate the logger through the Factory you first need to instantiate the Config component, as the Factory will require it to successfully instantiate the logger. The Config component has to provide the following three configuration items:
- logger.name - Used by Monolog as the name of the logger
- logger.loggerType - Used to determine which Monolog Logger Handler to use for the logger, value needs to match the name of the Handler class, currently only StreamHandler is supported
- logger.handlerArgs.<logger.loggerType> - Argument list that are going to be passed to the Handler instantiation
When all of the above is set, you may safely call the Factory::init method, and you will retrieve an instance of the logger in return.
$logger = \SlaxWeb\Logger\Factory::init($config);
If you wish to use the Service Provider, then you need to make sure that the Config components Service Provider is registered prior to trying to accessing the logger definition. Of course, the above configuration items are required as well. All that remains to do is to register the Service Provider of the logger, and it will define the logger instantiation to the logger.service key name.
$container->register(new \SlaxWeb\Logger\Service\Provider); $container["logger.service"]->addInfo("Logger loaded");