PHP code example of microparts / logs-php

1. Go to this page and download the library: Download microparts/logs-php 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/ */

    

microparts / logs-php example snippets


use Microparts\Logger\Logger;

$log = Logger::default(); // Psr\Log\LoggerInterface
$log->info('write something');

// this code uses Igni framework with Laravel DI container.
use Igni\Application\Providers\ServiceProvider;
use Monolog\Logger;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

class LoggerModule implements ServiceProvider
{
    /**
     * @param \Illuminate\Container\Container|ContainerInterface $container
     */
    public function provideServices($container): void
    {
        $container->singleton(LoggerInterface::class, function () {
            return Logger::default(); // it's all!
        });
    }
}

use Microparts\Logger\Logger;
use Psr\Log\LogLevel;

$log = new Logger('Haku', LogLevel::DEBUG); // enabled debug mode and set the channel name
$log->addErrorLogHandler();
$log->register();

$log->getMonolog()->info('Let\'s fly!');

use Microparts\Logger\Logger;
use Monolog\Handler\HandlerInterface;
use Monolog\Handler\NullHandler;
use Psr\Log\LogLevel;

$log = new Logger('Sen', LogLevel::DEBUG); // enabled debug mode and set the channel name
$log->addErrorLogHandler();
$log->addHandler(function (string $level): HandlerInterface {
    return new NullHandler($level);
});

$log->register();

$log->getMonolog()->info('Diligence is the mother of success');
bash
[2019-04-29 21:39:52] Server.INFO: CONFIG_PATH = ./configuration  
[2019-04-29 21:39:52] Server.INFO: STAGE = local  
[2019-04-29 21:39:52] Server.INFO: Configuration module loaded  
[2019-04-29 21:39:52] Server.INFO: HTTP static server started at 0.0.0.0:8080  
 
bash
composer