承接 gelembjuk/logger 相关项目开发

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

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

gelembjuk/logger

Composer 安装命令:

composer require gelembjuk/logger

包简介

Allows to add logging functions to different classes, helps to handle errors, log errors and display error screen. Can catch warnings and fatal errors

README 文档

README

PHP Package for easy logging and error catching. FileLogger class based on Psr/Log helps to filter what to log. ErrorScreen class helps to catch PHP Warnings and Fatal errors and display correct error screen to a user. ApplicationLogger is a trait to include logger in different classes very easy

Installation

Using composer: gelembjuk/logger require: {"gelembjuk/logger": "*"}

Configuration

Configuration is done in run time with a constructor options (as hash argument)

Configure FileLogger

logfile path to your log file (where to write logs) groupfilter list of groups of events to log. all means log everything. Groups separated with | symbol

$logger1 = new Gelembjuk\Logger\FileLogger(
	array(
		'logfile' => $logfile,  // path to your log file (where to write logs)
		'groupfilter' => 'group1|group2|group3'  // list of groups of events to log. `all` means log everything
	));

Configure ErrorScreen

catchwarnings - (true|false) . If true then user error handler is set to catch warnings

catchfatals - (true|false) . If true then fatal errors are catched. Use to log error and show normal error screen

catchexceptions - (true|false) . If true then uncatched exceptions will be catched by the object. Use this to catch exceptions missed in any try {} catch block

showwarningmessage - (true|false) . If true then error screen is displayed in case of warning. If is false then error is only logged

showfatalmessage - (true|false) . Display error screen for fatal errors. If false then only log is dine. User will see standard fatal error in this case

viewformat - set vaue for the viewformat variable. Possible values: html, json, xml, http . html is default value

showtrace - (true|false). Switcher to know if to show error trace for a user as part of error screen

commonerrormessage - string Common error message to show to a user when error happens

logger - Object of FileLogger class

loggeroptions - Options to create new FileLogger object

$errors = new Gelembjuk\Logger\ErrorScreen(
		array(
			'logger' => $logger1 /*create before*/,
			'viewformat' => 'html',
			'catchwarnings' => true,
			'catchfatals' => true,
			'showfatalmessage' => true,
			'commonerrormessage' => 'Sorry, somethign went wrong. We will solve ASAP'
		)
	);

Usage

FileLogger

require '../vendor/autoload.php';

$logger1 = new Gelembjuk\Logger\FileLogger(
	array(
		'logfile' => '/tmp/log.txt',
		'groupfilter' => 'all' // log everything this time
	));

// do test log write
$logger1->debug('Test log',array('group' => 'test'));

$logger1->setGroupFilter('group1|group2'); // after this only group1 and group2 events are logged

$logger1->debug('This message will not be in logs as `test` is out of filter',array('group' => 'test'));

ApplicationLogger trait

require '../vendor/autoload.php';

class A {
}

class B extends A {
	// include the trait to have logging functionality in this class
	use Gelembjuk\Logger\ApplicationLogger;
	
	public function __construct($logger) {
		$this->setLogger($logger);

		$this->logQ('B object create','construct|B');
	}

	public function doSomething() {
		$this->logQ('doSomething() in B','B');
	}
}

class C {
	use Gelembjuk\Logger\ApplicationLogger;
	
	public function __construct($logger) {
		$this->setLogger($logger);

		$this->logQ('C object create','construct|C');
	}

	public function doOtherThing() {
		$this->logQ('oOtherThing() in C','C');
	}
}

$b = new B($logger1); // $logger1 is instance of FileLogger
$c = new C($logger1);

$b->doSomething();
$c->doOtherThing();

ErrorScreen

require '../vendor/autoload.php';

$errors = new Gelembjuk\Logger\ErrorScreen(
		array(
			'logger' => $logger1 /*created before*/,
			'viewformat' => 'html',
			'catchwarnings' => true,
			'catchfatals' => true,
			'showfatalmessage' => true,
			'commonerrormessage' => 'Sorry, somethign went wrong. We will solve ASAP'
		)
	);

// to catch exceptions on the top level of the app
try {
	// do something 
	
} catch (Exception $e) {
	$errors->processError($e);
}

// presume there was no exception
// now catch warning

// warning is raised and catched in errors object
// error message displayed to a user
include('not_existent_file.php'); 	

Author

Roman Gelembjuk (@gelembjuk)

gelembjuk/logger 适用场景与选型建议

gelembjuk/logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 820 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 gelembjuk/logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gelembjuk/logger 我们能提供哪些服务?
定制开发 / 二次开发

基于 gelembjuk/logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 820
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 22
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-25