mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-25 03:48:24 +02:00
DAS and WHOIS update to use Monolog
This commit is contained in:
parent
0a4057f812
commit
0ecd7023d4
6 changed files with 261 additions and 87 deletions
42
das/helpers.php
Normal file
42
das/helpers.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
|
||||
/**
|
||||
* Sets up and returns a Logger instance.
|
||||
*
|
||||
* @param string $logFilePath Full path to the log file.
|
||||
* @param string $channelName Name of the log channel (optional).
|
||||
* @return Logger
|
||||
*/
|
||||
function setupLogger($logFilePath, $channelName = 'app') {
|
||||
// Create a log channel
|
||||
$log = new Logger($channelName);
|
||||
|
||||
// Set up the console handler
|
||||
$consoleHandler = new StreamHandler('php://stdout', Logger::DEBUG);
|
||||
$consoleFormatter = new LineFormatter(
|
||||
"[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
|
||||
"Y-m-d H:i:s.u", // Date format
|
||||
true, // Allow inline line breaks
|
||||
true // Ignore empty context and extra
|
||||
);
|
||||
$consoleHandler->setFormatter($consoleFormatter);
|
||||
$log->pushHandler($consoleHandler);
|
||||
|
||||
// Set up the file handler
|
||||
$fileHandler = new RotatingFileHandler($logFilePath, 0, Logger::DEBUG);
|
||||
$fileFormatter = new LineFormatter(
|
||||
"[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n",
|
||||
"Y-m-d H:i:s.u" // Date format
|
||||
);
|
||||
$fileHandler->setFormatter($fileFormatter);
|
||||
$log->pushHandler($fileHandler);
|
||||
|
||||
return $log;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue