public function setProperties($properties, $prefix) { $len = strlen($prefix); reset($properties); while (list($key, ) = each($properties)) { if (strpos($key, $prefix) === 0) { if (strpos($key, '.', $len + 1) > 0) { continue; } $value = Payone_Log4php_LoggerOptionConverter::findAndSubst($key, $properties); $key = substr($key, $len); if ($key == 'layout' and $this->obj instanceof Payone_Log4php_LoggerAppender) { continue; } $this->setProperty($key, $value); } } $this->activate(); }
/** * Configures a logger. * * @param Logger $logger The logger to configure * @param array $config Logger configuration options. */ private function configureLogger(Payone_Log4php_Logger $logger, $config) { $loggerName = $logger->getName(); // Set logger level if (isset($config['level'])) { $level = Payone_Log4php_LoggerLevel::toLevel($config['level']); if (isset($level)) { $logger->setLevel($level); } else { $default = $logger->getLevel(); $this->warn("Invalid level value [{$config['level']}] specified for logger [{$loggerName}]. Ignoring level definition."); } } // Link appenders to logger if (isset($config['appenders'])) { foreach ($config['appenders'] as $appenderName) { if (isset($this->appenders[$appenderName])) { $logger->addAppender($this->appenders[$appenderName]); } else { $this->warn("Nonexistnant appender [{$appenderName}] linked to logger [{$loggerName}]."); } } } // Set logger additivity if (isset($config['additivity'])) { $additivity = Payone_Log4php_LoggerOptionConverter::toBoolean($config['additivity'], null); if (is_bool($additivity)) { $logger->setAdditivity($additivity); } else { $this->warn("Invalid additivity value [{$config['additivity']}] specified for logger [{$loggerName}]. Ignoring additivity setting."); } } }
/** Setter function for string type. */ protected function setString($property, $value, $nullable = false) { if ($value === null) { if ($nullable) { $this->{$property} = null; } else { $this->warn("Null value given for '{$property}' property. Expected a string. Property not changed."); } } else { try { $this->{$property} = Payone_Log4php_LoggerOptionConverter::toStringEx($value); } catch (Exception $ex) { $value = var_export($value, true); $this->warn("Invalid value given for '{$property}' property: [{$value}]. Expected a string. Property not changed."); } } }
public static function substVars($val, $props = null) { $sbuf = ''; $i = 0; while (true) { $j = strpos($val, self::DELIM_START, $i); if ($j === false) { // no more variables if ($i == 0) { // this is a simple string return $val; } else { // add the tail string which contails no variables and return the result. $sbuf .= substr($val, $i); return $sbuf; } } else { $sbuf .= substr($val, $i, $j - $i); $k = strpos($val, self::DELIM_STOP, $j); if ($k === false) { // LoggerOptionConverter::substVars() has no closing brace. Opening brace return ''; } else { $j += self::DELIM_START_LEN; $key = substr($val, $j, $k - $j); // first try in System properties $replacement = Payone_Log4php_LoggerOptionConverter::getSystemProperty($key, null); // then try props parameter if ($replacement == null and $props !== null) { $replacement = @$props[$key]; } if (!empty($replacement)) { // Do variable substitution on the replacement string // such that we can solve "Hello ${x2}" as "Hello p1" // the where the properties are // x1=p1 // x2=${x1} $recursiveReplacement = Payone_Log4php_LoggerOptionConverter::substVars($replacement, $props); $sbuf .= $recursiveReplacement; } $i = $k + self::DELIM_STOP_LEN; } } } }