/**
  * Logs a message with a given log level by mapping the given parameters to
  * AgaviLogger compatible things. Does not log anything if the setting
  * 'core.use_logging' is disabled.
  *
  * @param mixed $level PSR-3 log level or an AgaviLoggerMessage instance
  * @param mixed $message string or object implementing __toString(); unused on AgaviLoggerMessage as $level
  * @param array $context arbitrary data to use for templated message; unused on AgaviLoggerMessage as $level
  *
  * @return void
  */
 public function log($level, $message, array $context = array())
 {
     if (!AgaviConfig::get('core.use_logging', true)) {
         return;
     }
     $logger_message = $level;
     // construct an AgaviLoggerMessage instance from PSR-3 parameters
     if (!$logger_message instanceof AgaviLoggerMessage) {
         $agavi_context = AgaviContext::getInstance();
         /* @var $logger_manager Honeybee\FrameworkBinding\Agavi\Logging\LoggerManager */
         $logger_manager = $agavi_context->getLoggerManager();
         $message = self::replacePlaceholders($message, $context);
         $level = Logger::getAgaviLogLevel($level);
         $class_name = $logger_manager->getDefaultMessageClass();
         /* @var $logger_message AgaviLoggerMessage */
         $logger_message = new $class_name();
         $logger_message->setLevel($level);
         $logger_message->setMessage($message);
         $logger_message->setParameter('psr3.context', $context);
         $logger_message->setParameter('scope', isset($context['scope']) ? $context['scope'] : LoggerManager::DEFAULT_MESSAGE_SCOPE);
     }
     $this->logger->log($logger_message);
 }
 /**
  * Creates and returns an AgaviLoggerMessage instance. To return a
  * different class set the default_message_class parameter in the
  * for the logger_manager entry in the factories.xml file.
  *
  * The log message parts need to be either strings, arrays or objects
  * implementing __toString(). Instances of the following classes are
  * treated in a special way automatically:
  * - Exception
  * - Honeybee\Infrastructure\Domain\Type - name of module
  * - Honeybee\Infrastructure\Domain\Model - uuid of resource
  * - AgaviValidationManager - messages of all incidents
  * - DateTime - ISO-8601 representation
  *
  * @see self::getAsString()
  *
  * If the log message consists of exactly two parts while the first is a
  * string and the second an associative array it is used as a PSR-3
  * compatible call and templating with the given context array according to
  * PSR-3 via {placeholders} is supported. This usage still includes getting
  * supported known types as strings. The given Agavi log level is being
  * converted to a PSR-3 compatible log level and the given scope is added
  * as a parameter to the message.
  *
  * @param int $log_level Agavi log level to use
  * @param string $scope name for the scope to use
  * @param mixed $log_message_parts string or object to log or array that contains log message parts
  *              ($log_message_parts or its array entries need to be of known types or implement __toString())
  *
  * @return AgaviLoggerMessage
  *
  * @throws InvalidArgumentException if __toString() is not callable on a log message part object
  */
 public function createLoggerMessage($log_level, $scope = self::DEFAULT_MESSAGE_SCOPE, $log_message_parts = "")
 {
     $text_message_parts = array();
     $class_name = $this->getDefaultMessageClass();
     $logger_message = new $class_name();
     $logger_message->setLevel($log_level);
     $logger_message->setParameter('scope', trim($scope));
     // might be a PSR-3 compatible log call with templated message and context array
     if (2 === count($log_message_parts) && is_string($log_message_parts[0]) && is_array($log_message_parts[1]) && ArrayToolkit::isAssoc($log_message_parts[1]) && false !== strpos($log_message_parts[0], '{')) {
         $logger_message->setParameter('psr3.context', $log_message_parts[1]);
         $logger_message->setLevel(Logger::getAgaviLogLevel($log_level));
         $logger_message->setMessage(Psr3Logger::replacePlaceholders($log_message_parts[0], $log_message_parts[1]));
         if (isset($log_message_parts[1]['scope'])) {
             $logger_message->setParameter('scope', $log_message_parts[1]['scope']);
         }
         return $logger_message;
     }
     $text = '';
     if (is_array($log_message_parts)) {
         // analyse log_message_parts to get nicely formatted strings for known classes etc.
         $text_message_parts = array();
         foreach ($log_message_parts as $log_message_part) {
             $text_message_parts[] = self::getAsString($log_message_part);
         }
         $text = implode(' ', $text_message_parts);
     } else {
         $text = self::getAsString($log_message_parts);
     }
     $logger_message->setMessage($text);
     return $logger_message;
 }