承接 nti/log-bundle 相关项目开发

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

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

nti/log-bundle

最新稳定版本:v3.0.0

Composer 安装命令:

composer require nti/log-bundle

包简介

Symfony NTILogBundle

关键字:

README 文档

README

Installation

  1. Install the bundle using composer:
$ composer require ntidev/log-bundle "dev-master"
  1. Add the bundle configuration to the AppKernel
public function registerBundles()
{
    $bundles = array(
        ...
        new NTI\LogBundle\NTILogBundle(),
        ...
    );
}
  1. Setup the configuration in the config.yml
# NTI
nti_log:
    exclude: [ 'JMose\CommandSchedulerBundle\Entity\ScheduledCommand' ]     # default: []

The exclude allows you to exclude logging for specific entities that change at a rapid rate (for example the User entity usually registers changes when users log in)

  1. Update the database schema
$ php app/console doctrine:schema:update

Usage

  1. Get the Logging service
$logger = $container->get('nti.logger');

The following methods are available for logging:

logNotice($message, $action = Log::ACTION_INFO, $entity = null)
logSuccess($message, $action = Log::ACTION_INFO, $entity = null)
logWarning($message, $action = Log::ACTION_INFO, $entity = null) 
logDebug($message, $action = Log::ACTION_DEBUG, $entity = null)
logError($message, $action = Log::ACTION_INFO, $entity = null)    
logException(\Exception $ex) 
logSlack($message, $level = Log::LEVEL_NOTICE, $entity = null) 

Example:

$service->logDebug("Hello World")

Event Listeners

The bundle comes with 2 event subscribers: DoctrineEventSubscriber and KernelExceptionListerner.

The DoctrineEventSubscriber will listener for the following events:

  • PostPersist
  • PostUpdate
  • PostRemove

And it will log the changes automatically into the database.

The KernelExceptionListener will capture all exceptions and log them into the database as well. However, if you capture an exception you must manually log it with the service, for example:

try {
    ...
    $em->flush()
} catch(\Exception $ex) {
    $this->get('nti.logger')->logException($ex);
    ...
}

Slack Integration

If the NexySlackBundle is used, you can integrate this bundle to throw the information to a channel in Slack as well.

The configuration piece as shown above serves to configure how the NTILogBundle should post to Slack:

# NTI
nti_log:
    ...    
    # In case NexySlackBundle is used
    nexy_slack:
        enabled:    # default: false
        replicate_logs: true     # default: false
        replicate_levels: [ERROR, DEBUG]   # default: [ERROR]
        channel: "#alertchannel"  # default: empty, required
        
# NexySlackBundle
nexy_slack:
    # The Slack API Incoming WebHooks URL.
    endpoint: "[see https://api.slack.com/tokens to generate the webhook for this app]"

Todo

  • Make the entity configurable and also the property used to get the username

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 7
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固