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




use Mellivora\Logger\LoggerFactory;
use Monolog\Level;

// Create factory instance
$factory = new LoggerFactory();

// Get default logger
$logger = $factory->get();
$logger->info('Hello World!');

// Use specific channel
$apiLogger = $factory->get('api');
$apiLogger->debug('API request processed');



// Using helper functions
mlog('info', 'User logged in', ['user_id' => 123]);
mlog_with('api', 'debug', 'API request');

// Using Facade
use Mellivora\Logger\Laravel\Facades\MLog;

MLog::info('Application started');
MLog::logWith('api', 'debug', 'API debug');
MLog::exception($exception, 'error');



use Mellivora\Logger\LoggerFactory;
use Mellivora\Logger\Config\LoggerConfig;

// Custom configuration
$config = new LoggerConfig([
    'default_channel' => 'app',
    'channels' => [
        'app' => [
            'handlers' => [
                [
                    'type' => 'rotating_file',
                    'path' => '/var/log/app.log',
                    'level' => 'info',
                    'max_files' => 30,
                ],
            ],
        ],
    ],
]);

$factory = new LoggerFactory($config);
$logger = $factory->get('app');



return [
    'default_channel' => env('MELLIVORA_LOG_CHANNEL', 'default'),

    'channels' => [
        'default' => [
            'handlers' => [
                [
                    'type' => 'rotating_file',
                    'path' => storage_path('logs/mellivora.log'),
                    'level' => env('MELLIVORA_LOG_LEVEL', 'debug'),
                    'max_files' => 30,
                ],
            ],
        ],

        'api' => [
            'handlers' => [
                [
                    'type' => 'rotating_file',
                    'path' => storage_path('logs/api.log'),
                    'level' => 'info',
                    'max_files' => 30,
                ],
            ],
        ],
    ],
];



// Helper functions
mlog('info', 'User action', ['action' => 'login', 'user_id' => 123]);
mlog_with('api', 'debug', 'API request', ['endpoint' => '/users']);

// Facade
use Mellivora\Logger\Laravel\Facades\MLog;

MLog::info('Application started');
MLog::error('Database connection failed', ['error' => $exception->getMessage()]);

// Exception logging
try {
    // Some operation
} catch (Exception $e) {
    MLog::exception($e, 'error', 'payment');
}
bash
php artisan vendor:publish --provider="Mellivora\Logger\Laravel\MellivoraLoggerServiceProvider"