Commit 6b6220e6 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

- FIX : Logger configuration et commande de test du logger

parent b5c2a33b
Loading
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -228,9 +228,6 @@ return array(
            'timesheet_modele' => realpath(__DIR__.'/../../data/timesheet_model.xls'),
        ],

        'log_path' => __DIR__ . '/../../logs/oscar.log',
        'log_level' => \Monolog\Logger::WARNING,

        'generated-documents' => [
            'activity' => []
        ],
+6 −2
Original line number Diff line number Diff line
@@ -67,13 +67,17 @@ class OscarCheckLoggerCommand extends OscarCommandAbstract
        $io->text("Envoi : <bold>$msg</bold> dans les logs");
        $logger->debug($msg);

        $msg = "Niveau INFO loggué";
        $io->text("Envoi : <bold>$msg</bold> dans les logs");
        $logger->info($msg);

        $msg = "Niveau NOTICE loggué";
        $io->text("Envoi : <bold>$msg</bold> dans les logs");
        $logger->notice($msg);

        $msg = "Niveau INFO loggué";
        $msg = "Niveau WARNING loggué";
        $io->text("Envoi : <bold>$msg</bold> dans les logs");
        $logger->info($msg);
        $logger->warning($msg);

        $msg = "Niveau ALERT loggué";
        $io->text("Envoi : <bold>$msg</bold> dans les logs");
+0 −2
Original line number Diff line number Diff line
@@ -172,9 +172,7 @@ class PublicController extends AbstractOscarController implements UseTimesheetSe
     */
    public function indexAction()
    {
        $this->getLoggerService()->debug("indexAction");
        $person = null;

        $validations = [];
        $isValidator = false;
        $person = $this->getOscarUserContextService()->getCurrentPerson();
+21 −4
Original line number Diff line number Diff line
@@ -11,6 +11,9 @@ namespace Oscar\Service;

use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
use Monolog\Handler\FirePHPHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Oscar\Exception\OscarException;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
@@ -20,8 +23,16 @@ class LoggerServiceFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $logPath = $container->get(OscarConfigurationService::class)->getConfiguration('log_path');
        $logLevel = $container->get(OscarConfigurationService::class)->getConfiguration('log_level');
        // --- CONF : issue de /config/autoload/global.php et /config/autoload/local.php

        /** @var OscarConfigurationService $configurationService */
        $configurationService = $container->get(OscarConfigurationService::class);

        // Emplacement du fichier de log
        $logPath = $configurationService->getLoggerFilePath();

        // Niveau de log
        $logLevel = $configurationService->getLoggerLevel();

        if( !file_exists($logPath) ){
            $handler = fopen($logPath, 'w');
@@ -36,8 +47,14 @@ class LoggerServiceFactory implements FactoryInterface
            throw new OscarException("Le fichier de log n'est pas accessible en écriture");
        }

        $logger = new \Monolog\Logger('oscar');
        $logger->pushHandler(new \Monolog\Handler\StreamHandler($logPath, $logLevel));
        // Sorties des logs (fichier + PHP stdrout)
        $stream = new StreamHandler($logPath, $logLevel);
        $firephp = new FirePHPHandler($logLevel);

        $logger = new Logger('oscar');
        $logger->pushHandler($stream);
        $logger->pushHandler($firephp);

        return $logger;
    }
}
+15 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
namespace Oscar\Service;


use Monolog\Logger;
use Oscar\Exception\OscarException;
use Oscar\Formatter\File\IHtmlToPdfFormatter;
use Oscar\Import\Data\DataStringArray;
@@ -82,6 +83,20 @@ class OscarConfigurationService implements ServiceLocatorAwareInterface
        ]);
    }

    /**
     * @return string
     */
    public function getLoggerFilePath() :string {
        return $this->getOptionalConfiguration('log_path', __DIR__.'/../../../../../logs/oscar.log');
    }

    /**
     * @return string
     */
    public function getLoggerLevel() :int {
        return $this->getOptionalConfiguration('log_level', Logger::WARNING);
    }


    /**
     * @param $key