31 lines
823 B
PHP
31 lines
823 B
PHP
|
|
No <?php
|
||
|
|
|
||
|
|
use Monolog\Logger;
|
||
|
|
use Monolog\Handler\StreamHandler;
|
||
|
|
|
||
|
|
if (!function_exists('base_path')) {
|
||
|
|
function base_path($path = '') {
|
||
|
|
return __DIR__ . '/../' . $path;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!function_exists('logger')) {
|
||
|
|
function logger(string $channel = 'app'): Logger {
|
||
|
|
static $loggers = [];
|
||
|
|
|
||
|
|
if (!isset($loggers[$channel])) {
|
||
|
|
$logger = new Logger($channel);
|
||
|
|
|
||
|
|
// Ensure logs directory exists
|
||
|
|
$logsDir = __DIR__ . '/../storage/logs';
|
||
|
|
if (!is_dir($logsDir)) {
|
||
|
|
mkdir($logsDir, 0755, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
$logger->pushHandler(new StreamHandler($logsDir . "/{$channel}.log", Logger::INFO));
|
||
|
|
$loggers[$channel] = $logger;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $loggers[$channel];
|
||
|
|
}
|
||
|
|
}
|