Monolog (Advanced Logging)

The artiframe add monolog command installs the monolog/monolog package, the industry standard logging library for PHP. Unlike the standard error_log() function, you can save your logs divided by days, send notifications to Telegram/Slack, or write them to a database.

💡 Information: Direct Usage
ArtiFrame does not copy a specific integration (Wrapper/Stub) class to the src/Service folder for this package. The installation simply includes the package into the project via Composer. The codes below are basic usage examples demonstrating the package's native operations. For more information, please review the Monolog Documentation.
Installation
terminal
$ artiframe add monolog
Usage Example (Logging to File)
Logger.php
<?php

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\RotatingFileHandler;

// 1. Create a Log Channel
$log = new Logger('system');

// 2. Add Handlers
// Example A: Write all logs to a single file (WARNING and above only)
$log->pushHandler(new StreamHandler(__DIR__.'/../../storage/logs/system.log', Logger::WARNING));

// Example B: Creates a separate log file for each day and retains the last 30 days
$log->pushHandler(new RotatingFileHandler(__DIR__.'/../../storage/logs/daily.log', 30, Logger::DEBUG));

// 3. Save Logs
// (The INFO level won't trigger the StreamHandler because we set the limit to WARNING. But it is written to RotatingFileHandler.)
$log->info('User logged into the system.', ['user_id' => 15]);

$log->warning('Storage space is 80% full.');

$log->error('Database connection lost!', [
    'ip' => $_SERVER['REMOTE_ADDR']
]);