libelulasoft/yii2-error-handler

Mongo数据库的错误处理器

安装次数: 10,566

依赖: 1

建议者: 0

安全性: 0

星标: 0

关注者: 0

分支: 1

类型:yii2-extension

2.1.0 2023-03-17 19:53 UTC

This package is auto-updated.

Last update: 2024-09-17 23:22:32 UTC


README

Mongo数据库的错误处理器

安装

安装此扩展的首选方法是通过 composer

运行以下命令之一:

composer require --prefer-dist libelulasoft/yii2-error-handler

或者

"libelulasoft/yii2-error-handler": "~1.0.0"

将以下内容添加到您的 composer.json 文件的 require 部分。

迁移

如果要从 taguz91/yii2-error-handler 版本迁移到新版本 libelulasoft/yii2-error-handler,请遵循以下步骤:

  1. 遵循 yii2-common-helpers 的迁移指南。

  2. 删除当前版本

composer remove taguz91/yii2-error-handler
  1. 安装新版本
composer require libelulasoft/yii2-error-handler
  1. 在整个项目中将命名空间 taguz91\ErrorHandler 更改为 Libelulasoft\ErrorHandler

  2. 更新库的配置,添加新的选项

  • bdConnection 将用于保存所有异常的数据库名称。
  • saveError 一个布尔值,指示我们是否应该在数据库中保存错误。
  • showTrace 一个布尔值,指示我们是否应该在响应中显示跟踪信息,默认使用 YII_DEBUG 常量。
  • saveBody 一个布尔值,指示我们是否应该在异常中保存通过 post 发送的数据,默认使用 YII_DEBUG 常量。
  1. 测试以确保一切按预期工作。

使用方法

扩展安装后,只需在代码中使用它即可:

// confing\main.php

'components' => [
  ...,
  'errorHandler' => [
    'errorAction' => 'site/error',
    'class' => \Libelulasoft\ErrorHandler\ErrorHandler::class,
    'loggerComponent' => '', // empty when the logger handler not exists
    'emailConfig' => 'EMAIL_ERROR_NOTIFICATION', // configuration for email
    'configClass' => '/common/models/Configuration', // debe implementar interface config
    'empresa' => $_GET['empresa'] ?? 'undefined',
    'bdConnection' => 'mongodb',
    'saveError' => true,
    'notificate' => true,
    'showTrace' => YII_DEBUG,
    'saveBody' => YII_DEBUG,
    // This exceptions not be save into database
    // And this exceptions not send via email
    'exceptionsNotSave' => [
      \Libelulasoft\ErrorHandler\exceptions\MessageException::class
    ],
  ],
]