當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Formatter\NormalizerFormatter類代碼示例

本文整理匯總了PHP中Monolog\Formatter\NormalizerFormatter的典型用法代碼示例。如果您正苦於以下問題:PHP NormalizerFormatter類的具體用法?PHP NormalizerFormatter怎麽用?PHP NormalizerFormatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了NormalizerFormatter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: log

 /**
  * Write a log entry.
  *
  * Example:
  * ```
  * use Google\Cloud\Logging\Logger;
  *
  * $psrLogger->log(Logger::ALERT, 'alert message');
  * ```
  *
  * ```
  * // Write a log entry using the context array with placeholders.
  * use Google\Cloud\Logging\Logger;
  *
  * $psrLogger->log(Logger::ALERT, 'alert: {message}', [
  *     'message' => 'my alert message'
  * ]);
  * ```
  *
  * ```
  * // Log information regarding an HTTP request
  * use Google\Cloud\Logging\Logger;
  *
  * $psrLogger->log(Logger::ALERT, 'alert message', [
  *     'stackdriverOptions' => [
  *         'httpRequest' => [
  *             'requestMethod' => 'GET'
  *         ]
  *     ]
  * ]);
  * ```
  *
  * @codingStandardsIgnoreStart
  * @param string|int $level The severity of the log entry.
  * @param string $message The message to log.
  * @param array $context {
  *     Context is an associative array which can include placeholders to be
  *     used in the `$message`. Placeholders must be delimited with a single
  *     opening brace `{` and a single closing brace `}`. The context will be
  *     added as additional information on the `jsonPayload`. Please note
  *     that the key `stackdriverOptions` is reserved for logging Google
  *     Stackdriver specific data.
  *
  *     @type array $stackdriverOptions['resource'] The
  *           [monitored resource](https://cloud.google.com/logging/docs/api/reference/rest/Shared.Types/MonitoredResource)
  *           to associate this log entry with. **Defaults to** type global.
  *     @type array $stackdriverOptions['httpRequest'] Information about the
  *           HTTP request associated with this log entry, if applicable.
  *           Please see
  *           [the API docs](https://cloud.google.com/logging/docs/api/reference/rest/Shared.Types/LogEntry#httprequest)
  *           for more information.
  *     @type array $stackdriverOptions['labels'] A set of user-defined
  *           (key, value) data that provides additional information about
  *           the log entry.
  *     @type array $stackdriverOptions['operation'] Additional information
  *           about a potentially long-running operation with which a log
  *           entry is associated. Please see
  *           [the API docs](https://cloud.google.com/logging/docs/api/reference/rest/Shared.Types/LogEntry#logentryoperation)
  *           for more information.
  * }
  * @throws InvalidArgumentException
  * @codingStandardsIgnoreEnd
  */
 public function log($level, $message, array $context = [])
 {
     $this->validateLogLevel($level);
     $options = [];
     if (isset($context['exception']) && $context['exception'] instanceof \Exception) {
         $context['exception'] = (string) $context['exception'];
     }
     if (isset($context['stackdriverOptions'])) {
         $options = $context['stackdriverOptions'];
         unset($context['stackdriverOptions']);
     }
     $formatter = new NormalizerFormatter();
     $processor = new PsrLogMessageProcessor();
     $processedData = $processor(['message' => (string) $message, 'context' => $formatter->format($context)]);
     $jsonPayload = [$this->messageKey => $processedData['message']];
     $entry = $this->logger->entry($jsonPayload + $processedData['context'], $options + ['severity' => $level]);
     $this->logger->write($entry);
 }
開發者ID:GoogleCloudPlatform,項目名稱:gcloud-php,代碼行數:81,代碼來源:PsrLogger.php

示例2: normalize

 protected function normalize($data)
 {
     if (is_bool($data) || is_null($data)) {
         return var_export($data, true);
     }
     return parent::normalize($data);
 }
開發者ID:laubosslink,項目名稱:lab,代碼行數:7,代碼來源:LineFormatter.php

示例3: format

 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $vars = parent::format($record);
     $output = $this->format;
     foreach ($vars['extra'] as $var => $val) {
         if (false !== strpos($output, '%extra.' . $var . '%')) {
             $output = str_replace('%extra.' . $var . '%', $this->stringify($val), $output);
             unset($vars['extra'][$var]);
         }
     }
     if ($this->ignoreEmptyContextAndExtra) {
         if (empty($vars['context'])) {
             unset($vars['context']);
             $output = str_replace('%context%', '', $output);
         }
         if (empty($vars['extra'])) {
             unset($vars['extra']);
             $output = str_replace('%extra%', '', $output);
         }
     }
     foreach ($vars as $var => $val) {
         if (false !== strpos($output, '%' . $var . '%')) {
             $output = str_replace('%' . $var . '%', $this->stringify($val), $output);
         }
     }
     return $output;
 }
開發者ID:HarveyCheng,項目名稱:myblog,代碼行數:30,代碼來源:LineFormatter.php

示例4: format

 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $record = parent::format($record);
     $record['tags'] = array();
     $record['custom_data'] = array();
     $record['timestamp'] = null;
     foreach (array('extra', 'context') as $source) {
         if (array_key_exists('tags', $record[$source]) && is_array($record[$source]['tags'])) {
             $record['tags'] = array_merge($record['tags'], $record[$source]['tags']);
         }
         if (array_key_exists('timestamp', $record[$source]) && is_numeric($record[$source]['timestamp'])) {
             $record['timestamp'] = $record[$source]['timestamp'];
         }
         unset($record[$source]['tags'], $record[$source]['timestamp']);
     }
     $record['custom_data'] = $record['extra'];
     $record['extra'] = array();
     foreach ($record['context'] as $key => $item) {
         if (!in_array($key, array('file', 'line', 'exception'))) {
             $record['custom_data'][$key] = $item;
             unset($record['context'][$key]);
         }
     }
     return $record;
 }
開發者ID:graze,項目名稱:monolog-extensions,代碼行數:28,代碼來源:RaygunFormatter.php

示例5: format

 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $record = parent::format($record);
     if (!isset($record['datetime'], $record['message'], $record['level'])) {
         throw new \InvalidArgumentException('The record should at least contain datetime, message and level keys, ' . var_export($record, true) . ' given');
     }
     $message = new Message();
     $message->setTimestamp($record['datetime'])->setShortMessage((string) $record['message'])->setHost($this->systemName)->setLevel($this->logLevels[$record['level']]);
     if (isset($record['channel'])) {
         $message->setFacility($record['channel']);
     }
     if (isset($record['extra']['line'])) {
         $message->setLine($record['extra']['line']);
         unset($record['extra']['line']);
     }
     if (isset($record['extra']['file'])) {
         $message->setFile($record['extra']['file']);
         unset($record['extra']['file']);
     }
     foreach ($record['extra'] as $key => $val) {
         $message->setAdditional($this->extraPrefix . $key, is_scalar($val) ? $val : $this->toJson($val));
     }
     foreach ($record['context'] as $key => $val) {
         $message->setAdditional($this->contextPrefix . $key, is_scalar($val) ? $val : $this->toJson($val));
     }
     if (null === $message->getFile() && isset($record['context']['exception']['file'])) {
         if (preg_match("/^(.+):([0-9]+)\$/", $record['context']['exception']['file'], $matches)) {
             $message->setFile($matches[1]);
             $message->setLine($matches[2]);
         }
     }
     return $message;
 }
開發者ID:sonfordson,項目名稱:Laravel-Fundamentals,代碼行數:36,代碼來源:GelfMessageFormatter.php

示例6: normalize

 protected function normalize($data)
 {
     if (is_object($data) && !$data instanceof \DateTime) {
         return $data;
     }
     return parent::normalize($data);
 }
開發者ID:joan16v,項目名稱:symfony2_test,代碼行數:7,代碼來源:WildfireFormatter.php

示例7: normalize

 /**
  * {@inheritdoc}
  */
 protected function normalize($data, int $depth = 0)
 {
     if (is_object($data) && !$data instanceof \DateTimeInterface) {
         return $data;
     }
     return parent::normalize($data, $depth);
 }
開發者ID:earncef,項目名稱:monolog,代碼行數:10,代碼來源:WildfireFormatter.php

示例8: format

 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     if (isset($record['context'])) {
         $record['context'] = parent::format($record['context']);
     }
     if (isset($record['extra'])) {
         $record['extra'] = parent::format($record['extra']);
     }
     if (!isset($record['datetime'], $record['message'], $record['level'])) {
         throw new \InvalidArgumentException('The record should at least contain datetime, message and level keys, ' . var_export($record, true) . ' given');
     }
     $message = new Message();
     $message->setTimestamp($record['datetime'])->setShortMessage((string) $record['message'])->setHost($this->systemName)->setLevel($this->logLevels[$record['level']]);
     // start count with message length + system name length + 200 for padding / metadata
     $len = 200 + strlen((string) $record['message']) + strlen($this->systemName);
     if ($len > self::MAX_LENGTH) {
         $message->setShortMessage(substr($record['message'], 0, self::MAX_LENGTH - 200));
         return $message;
     }
     if (isset($record['channel'])) {
         $message->setFacility($record['channel']);
         $len += strlen($record['channel']);
     }
     if (isset($record['extra']['line'])) {
         $message->setLine($record['extra']['line']);
         $len += 10;
         unset($record['extra']['line']);
     }
     if (isset($record['extra']['file'])) {
         $message->setFile($record['extra']['file']);
         $len += strlen($record['extra']['file']);
         unset($record['extra']['file']);
     }
     foreach ($record['extra'] as $key => $val) {
         $val = is_scalar($val) || null === $val ? $val : $this->toJson($val);
         $len += strlen($this->extraPrefix . $key . $val);
         if ($len > self::MAX_LENGTH) {
             $message->setAdditional($this->extraPrefix . $key, substr($val, 0, self::MAX_LENGTH - $len));
             break;
         }
         $message->setAdditional($this->extraPrefix . $key, $val);
     }
     foreach ($record['context'] as $key => $val) {
         $val = is_scalar($val) || null === $val ? $val : $this->toJson($val);
         $len += strlen($this->contextPrefix . $key . $val);
         if ($len > self::MAX_LENGTH) {
             $message->setAdditional($this->contextPrefix . $key, substr($val, 0, self::MAX_LENGTH - $len));
             break;
         }
         $message->setAdditional($this->contextPrefix . $key, $val);
     }
     if (null === $message->getFile() && isset($record['context']['exception']['file'])) {
         if (preg_match("/^(.+):([0-9]+)\$/", $record['context']['exception']['file'], $matches)) {
             $message->setFile($matches[1]);
             $message->setLine($matches[2]);
         }
     }
     return $message;
 }
開發者ID:intelogie,項目名稱:monolog,代碼行數:62,代碼來源:GelfMessageFormatter.php

示例9: __construct

 /**
  * @param string $dateFormat The format of the timestamp: one supported by DateTime::format.
  * @param array $labeling Associative array of a Monolog record to a LTSV record mapping.
  * @param bool $includeContext Whether to include context fields in a LTSV record.
  * @param bool $includeExtra Whether to include extra fields in a LTSV record.
  * @param array $labelReplacement Rule of replacement for LTSV labels.
  * @param array $valueReplacement Rule of replacement for LTSV values.
  */
 public function __construct($dateFormat = null, array $labeling = array('datetime' => 'time', 'level_name' => 'level', 'message' => 'message'), $includeContext = true, $includeExtra = true, array $labelReplacement = array("\r" => '', "\n" => '', "\t" => '', ':' => ''), array $valueReplacement = array("\r" => '\\r', "\n" => '\\n', "\t" => '\\t'))
 {
     parent::__construct($dateFormat);
     $this->labeling = $labeling;
     $this->includeContext = $includeContext;
     $this->includeExtra = $includeExtra;
     $this->labelReplacement = $labelReplacement;
     $this->valueReplacement = $valueReplacement;
 }
開發者ID:fjyuu,項目名稱:monolog-ltsv-formatter,代碼行數:17,代碼來源:LtsvFormatter.php

示例10: formatBatch

 public function formatBatch(array $records)
 {
     $bulk = ['body' => []];
     foreach ($records as $record) {
         $bulk['body'][] = ['index' => ['_index' => $this->index, '_type' => $this->type]];
         $bulk['body'][] = parent::format($record);
     }
     return $bulk;
 }
開發者ID:atrapalo,項目名稱:monolog-elasticsearch,代碼行數:9,代碼來源:ElasticsearchFormatter.php

示例11: normalize

 protected function normalize($data)
 {
     $data = parent::normalize($data);
     if (is_array($data)) {
         foreach ($data as $key => &$value) {
             if (is_array($value)) {
                 $value = json_encode($value);
             }
         }
     }
     return $data;
 }
開發者ID:BlueTM,項目名稱:LexikMonologBrowserBundle,代碼行數:12,代碼來源:NormalizerFormatter.php

示例12: format

 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $vars = parent::format($record);
     $output = '';
     $time = 0;
     if (!empty($vars['extra']['executionTime'])) {
         $time = $vars['extra']['executionTime'];
     }
     $output .= sprintf('[%10.3F]', round($time, 3));
     $output .= ' ' . sprintf('(%-9s)', !empty($vars['level_name']) ? $vars['level_name'] : '');
     $output .= ' ' . (!empty($vars['message']) ? $this->stringify($vars['message']) : '');
     return $output . "\n";
 }
開發者ID:wackamole0,項目名稱:rainmaker-tool,代碼行數:16,代碼來源:TaskLogFormatter.php

示例13: format

 /**
  *
  * {@inheritdoc}
  *
  */
 public function format(array $record)
 {
     $record = parent::format($record);
     $message = new Message();
     $message->setTimestamp($record['datetime'])->setShortMessage((string) $record['message'])->setFacility($record['channel'])->setHost($this->systemName)->setLine(isset($record['extra']['line']) ? $record['extra']['line'] : null)->setFile(isset($record['extra']['file']) ? $record['extra']['file'] : null)->setLevel($this->logLevels[$record['level']]);
     // Do not duplicate these values in the additional fields
     unset($record['extra']['line']);
     unset($record['extra']['file']);
     foreach ($record['extra'] as $key => $val) {
         $message->setAdditional($this->extraPrefix . $key, is_scalar($val) ? $val : $this->toJson($val));
     }
     foreach ($record['context'] as $key => $val) {
         $message->setAdditional($this->contextPrefix . $key, is_scalar($val) ? $val : $this->toJson($val));
     }
     return $message;
 }
開發者ID:vienbk91,項目名稱:fuelphp17,代碼行數:21,代碼來源:GelfMessageFormatter.php

示例14: format

 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $vars = parent::format($record);
     $output = $this->format;
     foreach ($vars['extra'] as $var => $val) {
         if (false !== strpos($output, '%extra.' . $var . '%')) {
             $output = str_replace('%extra.' . $var . '%', $this->replaceNewlines($this->convertToString($val)), $output);
             unset($vars['extra'][$var]);
         }
     }
     foreach ($vars as $var => $val) {
         if (false !== strpos($output, '%' . $var . '%')) {
             $output = str_replace('%' . $var . '%', $this->replaceNewlines($this->convertToString($val)), $output);
         }
     }
     return $output;
 }
開發者ID:TeamOfMalaysia,項目名稱:H,代碼行數:20,代碼來源:LineFormatter.php

示例15: format

 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $vars = parent::format($record);
     $output = "###############################################################\n###############################################################\n";
     $output = $output . $this->format;
     $valores = "";
     foreach ($vars['context'] as $var => $val) {
         $valores = $valores . "  " . $var . ": " . $val . "\n";
     }
     $output = str_replace('%context%', $valores, $output);
     foreach ($vars as $var => $val) {
         if (false !== strpos($output, '%' . $var . '%')) {
             $output = str_replace('%' . $var . '%', $this->convertToString($val), $output);
         }
     }
     return $output;
 }
開發者ID:bosonsymfony,項目名稱:excepciones-bundle,代碼行數:20,代碼來源:ExcepcionesFormatter.php


注:本文中的Monolog\Formatter\NormalizerFormatter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。