From 503ab544280f3d2f21c2018d7f9b30fa15d806a8 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 15 Sep 2017 16:37:19 +0200 Subject: [PATCH] Miglioramento nella gestione dei log --- core.php | 25 +++++++++++-------------- lib/functions.php | 15 +++++++++------ templates/base/settings.php | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/core.php b/core.php index ce253e557..dd8727da1 100644 --- a/core.php +++ b/core.php @@ -38,11 +38,15 @@ if (!empty($redirectHTTPS) && !isHTTPS(true)) { // $debug = true; // Logger per la segnalazione degli errori -$logger = new Monolog\Logger('OpenSTAManager'); +$logger = new Monolog\Logger('Logs'); $logger->pushProcessor(new Monolog\Processor\UidProcessor()); $logger->pushProcessor(new Monolog\Processor\WebProcessor()); +// Registrazione globale del logger +Monolog\Registry::addLogger($logger, 'logs'); + use Monolog\Handler\StreamHandler; +use Monolog\Handler\FilterHandler; use Monolog\Handler\RotatingFileHandler; $handlers = []; @@ -51,6 +55,9 @@ if (!API::isAPIRequest()) { $handlers[] = new StreamHandler(__DIR__.'/logs/error.log', Monolog\Logger::ERROR); $handlers[] = new StreamHandler(__DIR__.'/logs/setup.log', Monolog\Logger::EMERGENCY); + // Impostazione dei log estesi (per monitorare in modo completo le azioni degli utenti) + $handlers[] = new StreamHandler(__DIR__.'/logs/info.log', Monolog\Logger::INFO); + // Impostazioni di debug if (!empty($debug)) { // Ignoramento degli avvertimenti e delle informazioni relative alla deprecazione di componenti @@ -85,9 +92,10 @@ if (empty($debug)) { } // Imposta il formato di salvataggio dei log -$monologFormatter = new Monolog\Formatter\LineFormatter('[%datetime%] %channel%.%level_name%: %message% %extra%'.PHP_EOL); +$monologFormatter = new Monolog\Formatter\LineFormatter('[%datetime%] %channel%.%level_name%: %message%'.PHP_EOL.'%extra% '.PHP_EOL); foreach ($handlers as $handler) { - $logger->pushHandler($handler->setFormatter($monologFormatter)); + $handler->setFormatter($monologFormatter); + $logger->pushHandler(new FilterHandler($handler, [$handler->getLevel()])); } // Imposta Monolog come gestore degli errori @@ -154,17 +162,6 @@ if (!API::isAPIRequest()) { // Registrazione globale del template per gli input HTML register_shutdown_function('translateTemplate'); - // Impostazione dei log estesi (per monitorare in modo completo le azioni degli utenti) - if (!empty($operations_log)) { - $operations = $logger->withName('Debug'); - - $operationsFormatter = new Monolog\Formatter\LineFormatter('[%datetime%] %channel%.%level_name%: %message% %context% %extra%'.PHP_EOL); - - $handler = new StreamHandler(__DIR__.'/logs/info.log', Monolog\Logger::INFO); - - $operations->pushHandler($handler->setFormatter($operationsFormatter)); - } - // Impostazione della sessione di base $_SESSION['infos'] = array_unique((array) $_SESSION['infos']); $_SESSION['warnings'] = array_unique((array) $_SESSION['warnings']); diff --git a/lib/functions.php b/lib/functions.php index c05056c71..426dce7ad 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -586,7 +586,7 @@ function translateTemplate() global $id_module; global $id_record; global $id_plugin; - global $operations; + global $operations_log; $template = ob_get_clean(); @@ -597,13 +597,14 @@ function translateTemplate() $template = str_replace('$id_record$', $id_record, $template); // Completamento delle informazioni estese sulle azioni dell'utente - if (Auth::check() && !empty($operations) && !empty($_SESSION['infos'])) { + if (Auth::check() && !empty($operations_log) && !empty($_SESSION['infos'])) { $user = Auth::user(); + $logger = Monolog\Registry::getInstance('logs'); foreach ($_SESSION['infos'] as $value) { - $operations->addRecord(\Monolog\Logger::INFO, $value, [ + $logger->info($value.PHP_EOL.json_encode([ 'user' => $user['username'], - ]); + ])); } } @@ -827,17 +828,19 @@ function sum($first, $second = null, $decimals = null) function redirectOperation($id_module, $id_record) { $backto = filter('backto'); + // Scelta del redirect dopo un submit if (!empty($backto)) { $hash = filter('hash'); $hash = !starts_with($hash, '#') ? '#'.$hash : $hash; + if ($backto == 'record-edit') { redirect(ROOTDIR.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.$hash); - exit(); } elseif ($backto == 'record-list') { redirect(ROOTDIR.'/controller.php?id_module='.$id_module.$hash); - exit(); } + + exit(); } } diff --git a/templates/base/settings.php b/templates/base/settings.php index 620835ef2..fe10a0638 100644 --- a/templates/base/settings.php +++ b/templates/base/settings.php @@ -1,7 +1,7 @@ 'L', + 'orientation' => 'P', 'format' => 'A4', 'font-size' => 10, 'margins' => [