承接 interfasys/lognormalizer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

interfasys/lognormalizer

最新稳定版本:v1.0

Composer 安装命令:

composer require interfasys/lognormalizer

包简介

Parses variables and converts them to string so that they can be logged

README 文档

README

Scrutinizer Code Quality Code Climate Build Status Code Coverage

Parses variables and converts them to string so that they can be logged

Based on the Monolog formatter/normalizer.

How to use

Initialisation in your class

use InterfaSys\LogNormalizer\Normalizer;

$normalizer = new Normalizer();

The constructor supports the following optional arguments

  • int $maxRecursionDepth: The maximum depth at which you want to go in objects and arrays
  • int $maxArrayItems: The maximum number of elements you want to show, when parsing an array or an object
  • string $dateFormat: The format to apply to dates

Format variables before logging them

This is what your logging function could look like

/**
 * Converts the variables in the received log message to string before
 * sending everything to the real logger
 *
 * @param string $level
 * @param string $message
 * @param array $variables
 *
 * @return mixed
 */
public function log($level, $message, array $variables= []) {
	array_walk($variables, [$this->normalizer, 'format']);
	
	// Then use your current PSR-3 compatible logging system
	$this->logger->log($level, $message, $variables);
}

And you would call it like this from another class

$myLogger->log('debug',
	'Logger test {var1}, {var2}',
	[
		'var1' => $var1,
		'var2' => $var2
		]
);

Convert a single variable to a string

$normalizedVariable = $this->normalizer->format($variable);

统计信息

  • 总下载量: 1.12M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: AGPL-3.0
  • 更新时间: 2015-04-24