Exemplo n.º 1
0
 protected function createLogger()
 {
     $handlers = array();
     $fileLogging = $this->getParameter('log_file');
     $gelfLogging = $this->getParameter('gelf_server');
     if ($fileLogging || $gelfLogging) {
         $logStart = $this->getParameter('log_start');
         // Save when the first log started
         if (!$logStart) {
             $parameters = $this->getWordPressContext()->optionGet('mwp_container_parameters');
             $parameters['log_start'] = time();
             $this->getWordPressContext()->optionSet('mwp_container_parameters', $parameters);
         }
         // Logs can only go on for two days, always delete them after that
         if ($logStart && time() - $logStart > 172800) {
             // delete log file and disable logging
             @unlink(dirname(__FILE__) . '/../../../' . $fileLogging);
             $parameters = $this->getWordPressContext()->optionGet('mwp_container_parameters');
             $fileLogging = null;
             $gelfLogging = null;
             $parameters['gelf_server'] = null;
             $parameters['log_file'] = null;
             $parameters['log_start'] = false;
             $this->getWordPressContext()->optionSet('mwp_container_parameters', $parameters);
         }
     } elseif (@file_exists(dirname(__FILE__) . '/../../../' . $fileLogging)) {
         @unlink(dirname(__FILE__) . '/../../../' . $fileLogging);
     }
     if ($fileLogging && ($logFile = $this->createLogStream($fileLogging))) {
         $fileHandler = new Monolog_Handler_StreamHandler($logFile);
         $fileHandler->setFormatter(new Monolog_Formatter_HtmlFormatter());
         $handlers[] = $fileHandler;
     }
     if ($gelfLogging) {
         $publisher = $this->getGelfPublisher();
         $handlers[] = new Monolog_Handler_LegacyGelfHandler($publisher);
     }
     $processors = array();
     if (count($handlers) > 0) {
         // We do have some loggers set up.
         $processors += array(array(new Monolog_Processor_MemoryUsageProcessor(), 'callback'), array(new Monolog_Processor_MemoryPeakUsageProcessor(), 'callback'), array(new Monolog_Processor_IntrospectionProcessor(), 'callback'), array(new Monolog_Processor_PsrLogMessageProcessor(), 'callback'), array(new Monolog_Processor_UidProcessor(), 'callback'), array(new Monolog_Processor_WebProcessor(), 'callback'), array(new MWP_Monolog_Processor_TimeUsageProcessor(), 'callback'), array(new MWP_Monolog_Processor_ExceptionProcessor(), 'callback'), array(new MWP_Monolog_Processor_ProcessProcessor(), 'callback'), array(new MWP_Monolog_Processor_RequestIdProcessor($this->getParameter('request_id')), 'callback'));
     }
     // Always push this handler, because Monolog attaches an STDERR handler if there's no other present.
     $handlers[] = new Monolog_Handler_NullHandler(1000);
     $logger = new Monolog_Logger('worker', $handlers, $processors);
     return $logger;
 }
Exemplo n.º 2
0
 protected function createLogger()
 {
     $handlers = array();
     if ($this->getParameter('log_file') && ($logFile = $this->createLogStream($this->getParameter('log_file')))) {
         $fileHandler = new Monolog_Handler_StreamHandler($logFile);
         $fileHandler->setFormatter(new Monolog_Formatter_HtmlFormatter());
         $handlers[] = $fileHandler;
     }
     if ($this->getParameter('gelf_server')) {
         $publisher = new Gelf_Publisher($this->getParameter('gelf_server'), $this->getParameter('gelf_port') ? $this->getParameter('gelf_port') : Gelf_Publisher::GRAYLOG2_DEFAULT_PORT);
         $handlers[] = new Monolog_Handler_LegacyGelfHandler($publisher);
     }
     $processors = array();
     if (count($handlers) > 0) {
         // We do have some loggers set up.
         $processors += array(array(new Monolog_Processor_MemoryUsageProcessor(), 'callback'), array(new Monolog_Processor_MemoryPeakUsageProcessor(), 'callback'), array(new Monolog_Processor_IntrospectionProcessor(), 'callback'), array(new Monolog_Processor_PsrLogMessageProcessor(), 'callback'), array(new Monolog_Processor_UidProcessor(), 'callback'), array(new Monolog_Processor_WebProcessor(), 'callback'), array(new MWP_Monolog_Processor_TimeUsageProcessor(), 'callback'), array(new MWP_Monolog_Processor_ExceptionProcessor(), 'callback'), array(new MWP_Monolog_Processor_ProcessProcessor(), 'callback'));
     } else {
         $handlers[] = new Monolog_Handler_NullHandler();
     }
     $logger = new Monolog_Logger('worker', $handlers, $processors);
     return $logger;
 }