• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Formatter\NormalizerFormatter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Monolog\Formatter\NormalizerFormatter的典型用法代码示例。如果您正苦于以下问题:PHP NormalizerFormatter类的具体用法?PHP NormalizerFormatter怎么用?PHP NormalizerFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了NormalizerFormatter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: testBatchFormat

 public function testBatchFormat()
 {
     $formatter = new NormalizerFormatter('Y-m-d');
     $formatted = $formatter->formatBatch(array(array('level_name' => 'CRITICAL', 'channel' => 'test', 'message' => 'bar', 'context' => array(), 'datetime' => new \DateTime(), 'extra' => array()), array('level_name' => 'WARNING', 'channel' => 'log', 'message' => 'foo', 'context' => array(), 'datetime' => new \DateTime(), 'extra' => array())));
     $this->assertEquals(array(array('level_name' => 'CRITICAL', 'channel' => 'test', 'message' => 'bar', 'context' => array(), 'datetime' => date('Y-m-d'), 'extra' => array()), array('level_name' => 'WARNING', 'channel' => 'log', 'message' => 'foo', 'context' => array(), 'datetime' => date('Y-m-d'), 'extra' => array())), $formatted);
 }
开发者ID:abouthalf,项目名称:archies-recipes,代码行数:6,代码来源:NormalizerFormatterTest.php


示例3: 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


示例4: 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


示例5: 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


示例6: 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


示例7: 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


示例8: 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


示例9: 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


示例10: __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


示例11: 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


示例12: 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


示例13: 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


示例14: 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


示例15: 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


示例16: 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


示例17: format

 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $record = parent::format($record);
     $message = $this->prepareMessage($record);
     return $this->toJson($message) . "\n";
 }
开发者ID:pdffiller,项目名称:laravel-monolog-kibana,代码行数:9,代码来源:KibanaFormatter.php


示例18: __construct

 /**
  * @param string $dateFormat The format of the timestamp: one supported by DateTime::format
  */
 public function __construct($dateFormat = null)
 {
     parent::__construct($dateFormat);
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:7,代码来源:HtmlFormatter.php


示例19: format

 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $record = parent::format($record);
     return $this->getDocument($record);
 }
开发者ID:saj696,项目名称:pipe,代码行数:8,代码来源:ElasticaFormatter.php


示例20: format

 public function format(array $record)
 {
     $normalized = parent::format($record);
     return LegacyLogger::format($normalized['channel'], $normalized['message'], $normalized);
 }
开发者ID:mb720,项目名称:mediawiki,代码行数:5,代码来源:LegacyFormatter.php



注:本文中的Monolog\Formatter\NormalizerFormatter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Handler\AbstractProcessingHandler类代码示例发布时间:2022-05-23
下一篇:
PHP Monolog\Logger类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap