/** * @param array $config * @return ManualOrDecoratedActivationStrategy * @throws InvalidConfigurationException */ public static function factory(array $config) { if (isset(self::$strategy)) { throw new RuntimeException("Cannot manufacture a second instance of this strategy, as the current instance is required for " . "explicit flushing of the log message buffer"); } $config = self::validateAndNormaliseConfig($config); self::$strategy = new ManualOrDecoratedActivationStrategy(new ErrorLevelActivationStrategy($config['action_level'])); return self::$strategy; }
/** * @dataProvider configurationTests * @param array $config * @param string $expectedExceptionMessageContains */ public function testItValidatesConfiguration(array $config, $expectedExceptionMessageContains) { $this->setExpectedException('EngineBlock_Log_InvalidConfigurationException', $expectedExceptionMessageContains); ManualOrErrorLevelActivationStrategyFactory::factory($config); }
/** * Flushes any currently buffered log messages and causes any subsequent messages to be directly written to their * destination. * * @param string $reason The message that will be logged after the currently buffered messages have been flushed. */ public function flushLog($reason) { $activationStrategy = EngineBlock_Log_Monolog_Handler_FingersCrossed_ManualOrErrorLevelActivationStrategyFactory::getManufacturedStrategy(); $logger = $this->getLog(); if ($activationStrategy) { $activationStrategy->activate(); $logger->notice($reason); } elseif ($this->getConfiguration()->debug) { $logger->notice(sprintf("No log buffer to flush. Reason given for flushing: '%s'.", $reason)); } else { $logger->warning(sprintf("Unable to flush the log buffer. Reason given for flushing: '%s'.", $reason)); } }