🔈 Factories that facilitate creation of Monolog logger objects
PHP
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
src
tests
.gitattributes
.gitignore
.php_cs
.scrutinizer.yml
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE
README.md
composer.json
phpunit.xml.dist

README.md

Monolog Factory

Build Status Code Quality Code Coverage Latest Version PDS Skeleton

Monolog Factory facilitates creation of Monolog logger objects.

Besides the generic factory, this package features one that is suitable for using Monolog with container-interop.

Installation

The preferred method of installation is via Composer. Run the following command to install the latest version of a package and add it to your project's composer.json:

composer require nikolaposa/monolog-factory

Usage

Generic factory

use Monolog\Formatter\HtmlFormatter;
use Monolog\Handler\NativeMailerHandler;
use Monolog\Logger;
use Monolog\Processor\PsrLogMessageProcessor;
use MonologFactory\LoggerFactory;

$loggerFactory = new LoggerFactory();

$logger = $loggerFactory->createLogger('my_logger', [
    'handlers' => [
        [
            'name' => NativeMailerHandler::class,
            'options' => [
                'to' => 'test@example.com',
                'subject' => 'Test',
                'from' => 'noreply@example.com',
                'level' => Logger::ALERT,
                'formatter' => [
                    'name' => HtmlFormatter::class,
                ],
            ],
        ],
    ],
    'processors' => [
        [
            'name' => PsrLogMessageProcessor::class,
        ],
    ],
]);

Container-interop factory configuration

use Monolog\Formatter\HtmlFormatter;
use Monolog\Handler\NativeMailerHandler;
use Monolog\Logger;
use Monolog\Processor\PsrLogMessageProcessor;
use MonologFactory\DiContainerLoggerFactory;

return [
    'logger' => [
        'my_logger' => [
            'name' => 'my_logger',
            'handlers' => [
                [
                    'name' => NativeMailerHandler::class,
                    'options' => [
                        'to' => 'test@example.com',
                        'subject' => 'Test',
                        'from' => 'noreply@example.com',
                        'level' => Logger::ALERT,
                        'formatter' => [
                            'name' => HtmlFormatter::class,
                        ],
                    ],
                ],
            ],
            'processors' => [
                [
                    'name' => PsrLogMessageProcessor::class,
                ],
            ],
        ],
    ],
    'di' => [
        'factories' => [
            'MyLogger1' => new DiContainerLoggerFactory('my_logger'),
            //... or more preferred/optimal way:
            'MyLogger2' => [DiContainerLoggerFactory::class, 'my_logger'],
        ],
    ],
];

See more examples.

Credits

License

Released under MIT License - see the License File for details.