59 lines
1.5 KiB
PHP
Executable File
59 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use Monolog\Logger;
|
|
use Monolog\Handler\StreamHandler;
|
|
|
|
class Log
|
|
{
|
|
private static $logger;
|
|
|
|
private static function getLogger()
|
|
{
|
|
if (!self::$logger) {
|
|
self::$logger = new Logger('syscms');
|
|
// Logs should be in /logs as per RULES.md
|
|
$logPath = __DIR__ . '/../../logs/app.log';
|
|
$logDir = dirname($logPath);
|
|
if (!is_dir($logDir)) {
|
|
mkdir($logDir, 0777, true);
|
|
}
|
|
self::$logger->pushHandler(new StreamHandler($logPath, Logger::DEBUG));
|
|
}
|
|
return self::$logger;
|
|
}
|
|
|
|
public static function info($message, array $context = [])
|
|
{
|
|
self::getLogger()->info($message, $context);
|
|
}
|
|
|
|
public static function error($message, array $context = [])
|
|
{
|
|
self::getLogger()->error($message, $context);
|
|
}
|
|
|
|
public static function warning($message, array $context = [])
|
|
{
|
|
self::getLogger()->warning($message, $context);
|
|
}
|
|
|
|
public static function debug($message, array $context = [])
|
|
{
|
|
self::getLogger()->debug($message, $context);
|
|
}
|
|
|
|
/**
|
|
* Specialized write for audit logs
|
|
*/
|
|
public static function write($message, $module = 'general', $context = [])
|
|
{
|
|
if (!is_array($context)) {
|
|
$context = [];
|
|
}
|
|
$context['module'] = $module;
|
|
self::getLogger()->info($message, $context);
|
|
}
|
|
}
|