PHP code example of mellivora / logger-factory

1. Go to this page and download the library: Download mellivora/logger-factory library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mellivora / logger-factory example snippets


$factory = Mellivora\Logger\LoggerFactory::build(

$factory = Mellivora\Logger\LoggerFactory::buildWith('config/logger.yaml');

$factory->get('cli');
// or
$factory['cli'];

$factory->get('foo');
// or
$factory['foo'];

$factory->get('foo')->withName('bar');

$factory->make('bar', ['cli', 'file']);

$factory->add('orders', $logger);
$factory->get('orders')->withName('order_create'); // copy from `orders`

$factory->setDefault('orders');

$logger->addFilter(function($level, &$message, &$context) {
    if (isset($context['password'])) {
        $context['password'] = '******';
    }

    $message = preg_replace('/password=[^&]+/', 'password=******', $message);

    return true;
});

$logger->addFilter(function($level, $message, $context) {
    return !isset($context['password']);
});

class PasswordFilter
{
    public function __invoke($level, $message, $context)
    {
        // ...
    }
}
$logger->addFilter(new PasswordFilter);

Mellivora\Logger\LoggerFactory::setRootPath('/your/application');

$filename = LoggerFactory::getRootPath() . '/' . $filename;